ESLint Plugin for React

7.37.5 · active · verified Sun Apr 19

eslint-plugin-react provides React-specific linting rules for ESLint, helping developers enforce best practices, identify potential bugs, and maintain consistent code styles in React projects. As of version 7.37.5, it supports a wide range of React features and idioms, including Hooks, JSX, and functional/class components. The project maintains an active development and release cadence, with frequent patch and minor updates to address issues and add new rules. Its key differentiators include comprehensive coverage of React patterns, automatic detection of React versions, and integration with ESLint's ecosystem for a robust static analysis setup. It is the de-facto standard for linting React codebases with ESLint.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to install `eslint-plugin-react` and configure it using both the legacy `.eslintrc.json` format (for ESLint < v9) and the new flat config `eslint.config.js` format (for ESLint v9+), including recommended presets and React version detection.

npm install --save-dev eslint eslint-plugin-react

// .eslintrc.json (Legacy ESLint config)
{
  "env": {
    "browser": true,
    "es2021": true,
    "node": true
  },
  "extends": [
    "eslint:recommended",
    "plugin:react/recommended",
    "plugin:react/jsx-runtime" // For React 17+ new JSX transform
  ],
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "ecmaVersion": "latest",
    "sourceType": "module"
  },
  "plugins": [
    "react"
  ],
  "settings": {
    "react": {
      "version": "detect" // Automatically detects React version
    }
  },
  "rules": {
    // Add or override specific rules here, e.g.,
    // "react/prop-types": "off"
  }
}

// For ESLint v9+ (eslint.config.js)
// You would need to install @eslint/js for `js.configs.recommended`
// import globals from "globals";
// import js from "@eslint/js";
// import reactPlugin from "eslint-plugin-react";

// export default [
//   js.configs.recommended,
//   {
//     files: ["**/*.{js,jsx,mjs,cjs,ts,tsx}"],
//     ...reactPlugin.configs.flat.recommended,
//     ...reactPlugin.configs.flat['jsx-runtime'], // For React 17+ new JSX transform
//     languageOptions: {
//       globals: {
//         ...globals.browser,
//         ...globals.node
//       },
//       parserOptions: {
//         ecmaFeatures: {
//           jsx: true
//         },
//         ecmaVersion: "latest",
//         sourceType: "module"
//       }
//     },
//     settings: {
//       react: {
//         version: "detect"
//       }
//     },
//     rules: {
//       // Add or override specific rules here
//     }
//   }
// ];

view raw JSON →