exhaustive-deps
Added in v0.5.1Configuration
rslint.config.ts
Rule Details
Verifies the list of dependencies for Hooks like useEffect, useCallback,
useMemo, useImperativeHandle and useLayoutEffect.
Reports missing, unnecessary or duplicate entries in the dependency array
of these Hooks, and offers a suggested fix. useInsertionEffect is checked
only when configured through additionalHooks or the shared settings below.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Options
The rule accepts a single options object:
additionalHooks(string regex, default empty): Check the named custom hooks with the callback at index 0 and dependencies at index 1. Names matchingEffect($|[^a-z])use effect-specific checks. Only matches bare-identifier callees —Foo.useBarandReact.useBarare NOT matched even if the identifier suffix is in the regex (mirrors upstream'snode === calleeNodegate). Falls back tosettings['react-hooks'].additionalEffectHookswhen omitted or empty.enableDangerousAutofixThisMayCauseInfiniteLoops(boolean, defaultfalse): Promote all edits from the first suggestion into a top-level autofix while keeping the suggestion array. Off by default because applying it without code review can introduce render loops.requireExplicitEffectDeps(boolean, defaultfalse): Require effect-style Hooks to receive a dependencies argument. An explicitundefinedsatisfies this requirement; omitting the argument does not.experimental_autoDependenciesHooks(string array, default[]): Skip dependency-array and missing-array state-update checks for the named Hooks when their deps argument isnull,undefinedor absent. Async callbacks, stale assignments and cleanup ref accesses are still checked. The Hook must already be recognized as a built-in or throughadditionalHooksor shared settings.useMemoanduseCallbackstill warn without an array.
Differences from ESLint
- Components written in Flow syntax (
component MyComp() { ... }orhook useFoo() { ... }) are not analyzed; the rule produces no diagnostics on them. - The order of diagnostics in the returned list may differ from ESLint. Diagnostics retain their source locations and associated fixes.
- For a state name beginning with a non-BMP character, the functional-update
hint preserves the complete first character. For example,
const [𐀀, setX] = useState(0); useEffect(() => setX(𐀀 + 1), []);suggestssetX(𐀀 => ...). ESLint truncates that character to one UTF-16 code unit, producing an unpaired surrogate. Dependency analysis and fixes are unaffected.