I have the counter component. I encapsulated the business logic with custom hook. Should I optimize functions by means useCallback
? If there is input onchange handler, will the situation be the same?
const increment = () => {
setCount(count + 1);
};
↓
const increment = useCallback(() => {
setCount(count + 1);
}, [count]);
setCount
to thedeps
array, but becausesetCount
's reference is always the same, explicitly passing it as a dependency doesn't change the behavior and this is equally correct. – Double