React Performance ESLint Plugin

3.3.3 · active · verified Sun Apr 19

eslint-plugin-react-perf is an ESLint plugin designed to identify and prevent common performance anti-patterns in React applications. It specifically targets situations where new object, array, function, or JSX literals are passed directly as props, which can lead to unnecessary re-renders in components using `React.memo` or `PureComponent` due to shallow comparison failures. The current stable version is 3.3.3. While the README doesn't explicitly state a release cadence, new features and bug fixes appear to be released as needed. Its key differentiator is its focused approach on these specific 'new literal as prop' performance issues, providing a direct solution to a common React optimization pitfall, particularly useful in larger applications or performance-critical components. It provides both `recommended` and `all` configurations for easy setup.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates setting up `eslint-plugin-react-perf` using the new flat configuration format (`eslint.config.js`), extending the recommended rules, and showing how to customize a specific rule to ignore certain native element attributes.

import reactPerfPlugin from 'eslint-plugin-react-perf';
import globals from 'globals';

export default [
  {
    files: ['**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx'],
    languageOptions: {
      parserOptions: {
        ecmaFeatures: {
          jsx: true
        },
        ecmaVersion: 'latest',
        sourceType: 'module'
      },
      globals: {
        ...globals.browser,
        ...globals.node
      }
    },
    plugins: {
      'react-perf': reactPerfPlugin
    },
    rules: {
      ...reactPerfPlugin.configs.flat.recommended.rules,
      // Example: Override a rule to ignore specific native elements for new object props
      'react-perf/jsx-no-new-object-as-prop': [
        'error',
        {
          'nativeAllowList': ['style', 'data-testid']
        }
      ]
    }
  }
];

view raw JSON →