eslint-plugin-react-hooks is the official ESLint plugin maintained by the React team, designed to enforce the fundamental Rules of React Hooks and other best practices within React applications. The current stable version is 7.1.1. This plugin is released in coordination with React and ESLint major versions, with frequent minor updates addressing bug fixes, performance improvements, and support for new ESLint versions (e.g., v10 support was added recently). A key differentiator is its official backing by Facebook/React, ensuring alignment with the latest React paradigms and potentially incorporating experimental 'React Compiler rules' to guide future optimizations and patterns.
npm install eslint-plugin-react-hooksVerified import paths — ran on the pinned version, not inferred.
Installs the plugin and demonstrates basic configuration using ESLint's modern Flat Config (`eslint.config.js`), enabling core and example compiler rules.
Upgrade to `eslint-plugin-react-hooks@7.1.1` or higher to resolve the missing rule error.
Migrate your ESLint configuration from `.eslintrc` to `eslint.config.js` using the Flat Config syntax as shown in the quickstart or ESLint documentation. The plugin provides `reactHooks.configs.flat.recommended` for easy migration.
Prefer designing custom Hooks that do not require external dependencies or provide a higher-level API that abstracts dependency management. Use `additionalHooks` very sparingly after careful consideration.
Always extend from `reactHooks.configs.flat.recommended` (for Flat Config) or `plugin:react-hooks/recommended` (for Legacy Config) to automatically receive updated and new recommended rules.
Upgrade `eslint-plugin-react-hooks` to version 7.1.1 or newer. If you are on a different version and encounter this, ensure the rule name is correct or remove it if it's deprecated.
Ensure `eslint-plugin-react-hooks` is installed (`npm install --save-dev eslint-plugin-react-hooks`). Verify your ESLint configuration (either `.eslintrc` or `eslint.config.js`) correctly references the plugin, e.g., in the `plugins` array or through `reactHooks.configs.flat.recommended`.
Ensure all React Hooks (e.g., `useState`, `useEffect`, `useContext`) are called only from within React function components, custom Hooks (functions prefixed with `use`), or from a function passed to a Hook (like the effect callback in `useEffect`).
Add all relevant variables (props, state, or functions from the component scope) that are used inside the Hook's callback to its dependency array. Alternatively, if the Hook should run on every render, remove the dependency array entirely (though this is rarely the desired behavior for performance).