- ESLint plugin React Hooks
exhaustive deps
rule will give you guidance.
Heuristic to keep the dependency array small: To remove functions from the dependency array try the following steps (in order):
- Function into
useEffect
hook - Function out of component
- Function with
useCallback
(see this CodeSandBox of our code (JS) for an example)
- Note:
useState
setter functions may be ommitted from the dependency array. React guarrantees that their identity will stay stable across re-renders for the lifetime of the component.