Files
react.dev/src/content/reference/eslint-plugin-react-hooks/index.md
Ricky c3d7560005 Blog post for React 19.2 (#8028)
* wip

* feedback and rm canary stuff

* tweak

* fix json

* more canary stuff

* fix link

* update dates

* update meta description

* Expand performance track section

* adjust linter note

* edit perf tracks down

* edit perf tracks down more

* tweak note

* tweak useEffectEvent

* formatting

* tweaks

* ppr

* rm canary stuff

* fix json

* fix json

* tweaks

* linter note

* nit

* nit

* link

* nit

* ppr

* missing await

* add lint v6

* fix link

---------

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
2025-10-01 17:42:52 -04:00

3.8 KiB
Raw Blame History

title, version
title version
eslint-plugin-react-hooks rc

eslint-plugin-react-hooks provides ESLint rules to enforce the Rules of React.

This plugin helps you catch violations of React's rules at build time, ensuring your components and hooks follow React's rules for correctness and performance. The lints cover both fundamental React patterns (exhaustive-deps and rules-of-hooks) and issues flagged by React Compiler. React Compiler diagnostics are automatically surfaced by this ESLint plugin, and can be used even if your app hasn't adopted the compiler yet.

When the compiler reports a diagnostic, it means that the compiler was able to statically detect a pattern that is not supported or breaks the Rules of React. When it detects this, it **automatically** skips over those components and hooks, while keeping the rest of your app compiled. This ensures optimal coverage of safe optimizations that won't break your app.

What this means for linting, is that you dont need to fix all violations immediately. Address them at your own pace to gradually increase the number of optimized components.

These rules are included in the recommended preset eslint-plugin-react-hooks:

  • exhaustive-deps - Validates that dependency arrays for React hooks contain all necessary dependencies
  • rules-of-hooks - Validates that components and hooks follow the Rules of Hooks

Additional Rules {/additional-rules/}

Starting in version 6.0, these rules are available to opt-in:

  • component-hook-factories - Validates higher order functions defining nested components or hooks
  • config - Validates the compiler configuration options
  • error-boundaries - Validates usage of Error Boundaries instead of try/catch for child errors
  • gating - Validates configuration of gating mode
  • globals - Validates against assignment/mutation of globals during render
  • immutability - Validates against mutating props, state, and other immutable values
  • incompatible-library - Validates against usage of libraries which are incompatible with memoization
  • preserve-manual-memoization - Validates that existing manual memoization is preserved by the compiler
  • purity - Validates that components/hooks are pure by checking known-impure functions
  • refs - Validates correct usage of refs, not reading/writing during render
  • set-state-in-effect - Validates against calling setState synchronously in an effect
  • set-state-in-render - Validates against setting state during render
  • static-components - Validates that components are static, not recreated every render
  • unsupported-syntax - Validates against syntax that React Compiler does not support
  • use-memo - Validates usage of the useMemo hook without a return value