exhaustive-deps
Configuration
rslint.config.ts
Rule Details
Verifies the list of dependencies for Hooks like useEffect, useCallback,
useMemo, useImperativeHandle, useLayoutEffect and useInsertionEffect.
Reports missing, unnecessary or duplicate entries in the second argument
of these Hooks, and offers a suggested fix.
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): Treat the named custom hooks as effect-style Hooks (callback at index 0). 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'].additionalHookswhen omitted or empty.enableDangerousAutofixThisMayCauseInfiniteLoops(boolean, defaultfalse): Promote the first suggestion's first fix 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 be passed an explicit deps array (orundefined). Useful in codebases that disable the deps-array fallback to make every effect's reactive surface explicit.experimental_autoDependenciesHooks(string array, default[]): Skip dependency analysis entirely for the named custom hooks when their deps argument isnullor absent (the hook is expected to infer deps itself). Used by tooling that does its own dep auto-injection.
Differences from ESLint
- Components written in Flow syntax (
component MyComp() { ... }orhook useFoo() { ... }) are not analyzed; the rule produces no diagnostics on them. - When multiple diagnostics are emitted for the same source line, the order in the diagnostics list may differ from ESLint. The set of diagnostics, their messages, and their fix outputs are identical; only the position of each entry within the array can vary. IDEs and CLI reporters that sort by source position display them identically.