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.