Should we use useCallback in every function handler in React Functional Components

The short answer is because arrow function is recreated every time, which will hurt the performance. This is a common misconception. The arrow function is recreated every time either way (although with useCallback subsequent ones may be thrown away immediately). What useCallback does is make it possible for the child component you use the callback … Read more

Passing a function in the useEffect dependency array causes infinite loop

The issue is that upon each render cycle, markup is redefined. React uses shallow object comparison to determine if a value updated or not. Each render cycle markup has a different reference. You can use useCallback to memoize the function though so the reference is stable. Do you have the react hook rules enabled for … Read more