React Best Practices

Chapter 7 · Practice 4 of 4

Enforce the Rules of React with the hooks lint plugin

From Testing React code

Why it matters

The eslint-plugin-react-hooks package checks:

  • the Rules of Hooks,
  • exhaustive dependencies,
  • in its current presets, the compiler-powered rules that catch impure renders and other patterns React Compiler cannot optimize.

The linter works even if you have not turned the compiler on yet. Use the recommended preset, run it in CI, and treat its errors as bugs.

If you used the older eslint-plugin-react-compiler, remove it. Its rules now live in the hooks plugin.

Example

JavaScript
// eslint.config.js
import reactHooks from 'eslint-plugin-react-hooks';
import { defineConfig } from 'eslint/config';

export default defineConfig([reactHooks.configs.flat.recommended]);