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.
npm install eslint-plugin-react-perfVerified import paths — ran on the pinned version, not inferred.
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.
For new projects or migration, use `import reactPerfPlugin from 'eslint-plugin-react-perf';` and `reactPerfPlugin.configs.flat.recommended` in your `eslint.config.js`. For legacy projects, continue to use `"extends": ["plugin:react-perf/recommended"]` in your `.eslintrc` file.
Utilize the `nativeAllowList` configuration option to ignore specific attributes on native HTML elements, or wrap your inline values in `useMemo` or `useCallback` hooks, or hoist them outside the render function/component.
Carefully review each rule and its documentation. Disable specific rules where conflicts are unavoidable and justified, or adjust the `nativeAllowList` for particular rules as needed.
Ensure `npm i eslint-plugin-react-perf` is run, and the plugin is added to your ESLint configuration. For `.eslintrc`, check `"plugins": ["react-perf"]`. For `eslint.config.js`, ensure `plugins: { 'react-perf': reactPerfPlugin }` is present.Verify that you are using `import reactPerfPlugin from 'eslint-plugin-react-perf';` and accessing the configuration via `reactPerfPlugin.configs.flat.recommended` (or `all`). Do not attempt to use `require` with `configs.flat`.
Run `npm dedupe` or `yarn install --flat` to resolve duplicate package versions. If the issue persists, manually inspect your `node_modules` for multiple installations of the plugin.