Registry / testing / eslint-plugin-react-hooks

eslint-plugin-react-hooks

JSON →
library7.1.1jsnpmunverified

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.

testing
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

This is the primary way to integrate the plugin with ESLint's Flat Config (`eslint.config.js` or `eslint.config.ts`), which primarily uses ES modules. For legacy `.eslintrc` configurations, the plugin is typically referenced via string identifiers (e.g., `'plugin:react-hooks/recommended'`) and does not require a direct JavaScript import in the configuration file itself.

import reactHooks from 'eslint-plugin-react-hooks';

Installs the plugin and demonstrates basic configuration using ESLint's modern Flat Config (`eslint.config.js`), enabling core and example compiler rules.

npm install --save-dev eslint-plugin-react-hooks eslint // eslint.config.js (for ESLint v9+ Flat Config) import reactHooks from 'eslint-plugin-react-hooks'; import { defineConfig } from 'eslint/config'; export default defineConfig([ { files: ['**/*.{js,jsx,ts,tsx}'], plugins: { 'react-hooks': reactHooks }, rules: { // Core hooks rules 'react-hooks/rules-of-hooks': 'error', 'react-hooks/exhaustive-deps': 'warn', // Example React Compiler rules (optional, consider 'recommended-latest') 'react-hooks/set-state-in-effect': 'error', 'react-hooks/static-components': 'error' } }, // Or simply use the recommended preset: // reactHooks.configs.flat.recommended, ]);
Debug
Known footguns
breakingVersion 7.1.0 temporarily removed the `component-hook-factories` rule, causing ESLint configuration errors for users referencing it. This was immediately patched in v7.1.1 by re-adding the rule as a deprecated no-op for backward compatibility.
breakingWith the release of ESLint v9 and its Flat Config system, older `.eslintrc` files are no longer directly supported. Users upgrading ESLint to v9+ must migrate their configuration to `eslint.config.js` (Flat Config).
gotchaThe `exhaustive-deps` rule includes an `additionalHooks` option to validate dependencies of custom Hooks, but its use is strongly discouraged by the React team. Over-reliance on this option can lead to brittle custom Hook APIs.
gotchaUsing custom rule configurations instead of the `recommended` or `recommended-latest` presets may result in missing new recommended rules as they are added in future plugin versions, leading to incomplete linting coverage.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
10 hits · last 30 days
gptbot
4
ahrefsbot
4
script
1
googlebot
1
Resources