Let’s say I have the following code for changing the input values and it updates the state of the component:
const handleInputChange = e => {
let value = e.target.value;
let name = e.target.name;
let type = e.target.type;
// some other code
setInput(nextState);
};
However, since I have different components using this same function, I’d like to make it an exportable utility function. But then it has the “setInput” function call coming from useState hook.
Should I just pass the setInput as a parameter to every handleInputChange() call like:
onChange={e => handleInputChange(e, setInput)}
Or is there a better way of handling this?