0
  const [loc, setLoc] = useState(default);
 
  const handleChanges = (event, data, setLocFunction) => {
        const storedLoc = [...data];

        storedLoc[event.target.dataset.id][event.target.name] = event.target.value;

        setLocFunction(storedLoc);
    };

That's my setup then in my JSX I am trying to pass those value to my handleChange function like so:

                                <input
                                className="ddRowLat"
                                type="text"
                                onChange={handleLocChanges(event, loc, setLoc}
                                key={index}
                                value={item.lat}
                                data-id={index}
                                name="lat"
                               />

but I'm encountering an eslint rule https://eslint.org/docs/rules/no-restricted-globals for the event. What's the correct solution to this issue?

1
  • I think it's just the "event" variable name. Try to change to "e" or something like that... Commented Oct 8, 2020 at 2:18

3 Answers 3

1

The smallest change you can make from what you have currently would be this:

onChange={event => handleLocChanges(event, loc, setLoc)}
Sign up to request clarification or add additional context in comments.

1 Comment

That was the simplest change out of all three recommendations. Thanks
0

Make handleChanges a HOF which, when called, returns a function that takes event as the first parameter:

const handleChanges = (data, setLocFunction) => event => {
onChange={handleLocChanges(loc, setLoc)}

Comments

0

Try to change the parameter name:

const handleChanges = (e, data, setLocFunction) => {
    const storedLoc = [...data];

    storedLoc[event.target.dataset.id][e.target.name] = e.target.value;

    setLocFunction(storedLoc);
};

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.