ESLint Plugin for React Hooks

7.1.1 · active · verified Sun Apr 19

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.

Common errors

Warnings

Install

Imports

Quickstart

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,
]);

view raw JSON →