The key distinction is that with the first approach, handleChange really ought to be a useCallback with input as a dependency, but with the function approach it is not necessary.
Iām not sure that several useStates is better, actually. How about a useReducer instead?
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Yeah, an object is probably not ideal for
useState, but you can optimize it by passing a function. Instead of doing this...setInput({...input, [name]: value})...you can do this:
setInput((prevState) => ({...prevState, [name]: value}))The key distinction is that with the first approach,
handleChangereally ought to be auseCallbackwithinputas a dependency, but with the function approach it is not necessary.Iām not sure that several
useStates is better, actually. How about auseReducerinstead?