I am Senior Reactjs developer with 4 year of experience. Apart from freelancing work I am a mentor teaching 100's of students around the globe. I love to share knowledge regarding Reactjs.
I am Senior Reactjs developer with 4 year of experience. Apart from freelancing work I am a mentor teaching 100's of students around the globe. I love to share knowledge regarding Reactjs.
I think your original code is correct and adding value as a dependency would be a mistake. It's not referenced inside the callback, nor should it be added as a dependency, otherwise your callback function would be re-created on every single value change, which would defy the purpose of using that callback hook there. There's no reason for your event handler to change when the input value changes.
React's console output usually contains good information and warning messages about missing dependencies. So if value or anything else was required for your callback you would see that in your log output.
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.
I think you need to pass value as dependency to useCallback instead of setValue ?
The value used inside handleChange is event.target.value different from outside value.
I mean instead of
const handleChange = useCallback(
event => {
setValue(event.target.value);
},
[setValue]
);
this you can write
const handleChange = useCallback(
event => {
setValue(event.target.value);
},
[value]
);
Hmm. I don't think value needs to be passed as dependency since it not being used but I need to check.
I think your original code is correct and adding
value
as a dependency would be a mistake. It's not referenced inside the callback, nor should it be added as a dependency, otherwise your callback function would be re-created on every single value change, which would defy the purpose of using that callback hook there. There's no reason for your event handler to change when the input value changes.React's console output usually contains good information and warning messages about missing dependencies. So if
value
or anything else was required for your callback you would see that in your log output.