Should I include setState in useCallback’s array of dependencies?

The recommendation for that is also on React Docs – Hooks API Reference.

The setState function is used to update the state. It accepts a new
state value and enqueues a re-render of the component.

setState(newState);

During subsequent re-renders, the first value
returned by useState will always be the most recent state after
applying updates.

Note

React guarantees that setState function identity is stable and won’t
change on re-renders. This is why it’s safe to omit from the useEffect
or useCallback dependency list.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)