Skip to content

use-exhaustive-dependencies

Checks hook dependency arrays against the values captured by the callback.

By default, the rule checks these hooks:

  • useEffect
  • useLayoutEffect
  • useInsertionEffect
  • useCallback
  • useMemo
  • useImperativeHandle
  • useSpring
  • useSprings
  • useTrail

It reports three broad problems:

  • a dependency array is missing when the closure captures reactive values
  • one or more dependencies are missing from the array
  • a dependency is unnecessary or unstable

The rule skips values it treats as stable, including imports, function declarations, class declarations, literal const values, module-level const values, stable hook results like setters from useState and useReducer, and values from hooks configured with stableResult.

It can also suggest edits for adding or removing dependencies.

Incorrect
function UserProfile({ userId }) {
useEffect(() => {
fetchUser(userId);
}, []);
}
Correct
function UserProfile({ userId }) {
useEffect(() => {
fetchUser(userId);
}, [userId]);
}
OptionTypeDefault
hooksHookEntry[][]
reportMissingDependenciesArraybooleantrue
reportUnnecessaryDependenciesbooleantrue

Each custom hook entry can define:

FieldTypeNotes
namestringHook name to track.
closureIndexnumberWhich argument contains the callback.
dependenciesIndexnumberWhich argument contains the dependency array.
stableResultboolean | number | number[] | string[]Marks the whole result, tuple indices, or object keys as stable.