# @arthurgeron/eslint-plugin-react-usememo

> This plugin enforces the wrapping of complex objects or functions (which might generate unnecessary renders or side-effects) in `useMemo` or `useCallback`. It also allows you to programmatically enforce the wrapping of functional components in `memo`, and

Latest version **3.0.1** (published 2026-05-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install @arthurgeron/eslint-plugin-react-usememo
pnpm add @arthurgeron/eslint-plugin-react-usememo
yarn add @arthurgeron/eslint-plugin-react-usememo
bun add @arthurgeron/eslint-plugin-react-usememo
```

## Health

**Score 50/100 (C)** — status: active.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 3.0.1 |
| Published | 2026-05-11 |
| First published | 2022-07-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 806.4 KB |
| Known vulnerabilities | 0 (+4 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 81 |
| Author | Stefano J. Attardi |
| Maintainers | arthurger0n |

## Links

- npm: https://www.npmjs.com/package/@arthurgeron/eslint-plugin-react-usememo
- Repository: https://github.com/arthurgeron/eslint-plugin-react-usememo
- Homepage: https://github.com/arthurgeron/eslint-plugin-react-usememo#readme
- Issues: https://github.com/arthurgeron/eslint-plugin-react-usememo/issues
- npm.io page: https://npm.io/package/@arthurgeron/eslint-plugin-react-usememo

## Dependencies (2)

- [uuid](https://npm.io/package/uuid.md) 13.0.0
- [minimatch](https://npm.io/package/minimatch.md) 10.1.1

## Recent versions

- 3.0.1 (latest) — 2026-05-11
- 2.5.0--beta5 (beta) — 2025-04-02
- 3.0.0 — 2026-01-31
- 2.5.0 — 2025-04-11
- 2.5.0--beta4 — 2025-04-01
- 2.5.0--beta3 — 2025-03-31
- 2.5.0--beta2 — 2025-03-13
- 2.5.0--beta1 — 2025-03-13
- 2.5.0--beta0 — 2024-12-15
- 2.4.4 — 2024-10-22
- 2.4.3 — 2024-10-07
- 2.4.2 — 2024-10-06
- 2.4.1 — 2024-08-14
- 2.4.0 — 2024-04-25
- 2.4.0--beta0 — 2024-03-17
- … 40 more at https://npm.io/package/@arthurgeron/eslint-plugin-react-usememo/versions

## README

# ESLint-Plugin-React-UseMemo

This plugin enforces the wrapping of complex objects or functions (which might generate unnecessary renders or side-effects) in `useMemo` or `useCallback`. It also allows you to programmatically enforce the wrapping of functional components in `memo`, and that all props and dependencies are wrapped in `useMemo`/`useCallback`.

## Purpose

The objective is to ensure that your application's component tree and/or expensive lifecycles (such as React Native's FlatLists, useEffect, useMemo, etc.) only re-calculate or render again when absolutely necessary. By controlling expensive expressions, you can achieve optimal scalability and performance for your application.

_**Note:**_ Use of memoization everywhere is not advised, as everything comes with a cost. Overusing memoization might slow down your application instead of speeding it up.

## Guidelines for Memoization

> For more details, please refer to React's [documentation](https://react.dev/reference/react/useMemo) on hooks, re-rendering and memoization.

### There are two primary rules for situations where dynamic objects should be memoed:

1. Variables or expressions that return non-primitive objects or functions passed as props to other components.

   **_Incorrect_**

   ```js
   function Component({ incomingData }) {
     const complexData = {
       ...incomingData,
       checked: true,
     }; // generated each render, breaks hooks shallow comparison

     return <SomeComponent data={complexData} />;
   }
   ```

   **_Correct_**

   ```js
   function Component({ incomingData }) {
     const complexData = useMemo(
       () => ({
         ...incomingData,
         checked: true,
       }),
       [incomingData],
     ); // generated only when incomingData changes

     return <SomeComponent data={complexData} />;
   }
   ```

2. Variables or expressions that return non-primitive objects returned from custom hooks.

   **_Incorrect_**

   ```js
   function useMyData({ incomingData }) {
     const parsedData = parseData(incomingData); // generated each render

     return parsedData; // Will result in loops passed as a dependency in other hooks(e.g. useMemo, useCallback, useEffect).
   }
   ```

   **_Correct_**

   ```js
   function useMyData({ incomingData }) {
     const parsedData = useMemo(() => parseData(incomingData), [incomingData]); // generated only when incomingData changes

     return parsedData; // Won't generate loops if used as a dependency in hooks.
   }
   ```

### It is not recommended to use memoization in the following cases:

- When the resulting value (expression or variable) is primitive (string, number, boolean).

  **_Incorrect_**

  ```js
  function Component() {
    const width = useMemo(() => someValue * 10, []); // results in integer, wouldn't break hooks' shallow comparison; Memoizing this would only reduce performance

    return <SomeComponent width={width} />;
  }
  ```

  **_Correct_**

  ```js
  function Component() {
    const width = someValue * 10;

    return <SomeComponent width={width} />;
  }
  ```

- If you're passing props to a native component of the framework (e.g. Div, Touchable, etc), except in some instances in react-native (e.g. FlatList).

  **_Incorrect_**

  ```js
  function Component() {
    const onClick = useCallback(() => {}, []);

    return <div onClick={onClick} />;
  }
  ```

  **_Correct_**

  ```js
  function Component() {
    const onClick = () => {};

    return <div onClick={onClick} />;
  }
  ```

- Values that can be a global/context outside the react Context.
  **_Incorrect_**

  ```js
  function Component() {
    const breakpoints = [100];

    return <Modal breakpoints={breakpoints}>
  }
  ```

  **_Correct_**

  ```js
  const breakpoints = [100];

  function Component() {
    return <Modal breakpoints={breakpoints}>
  }
  ```

## Installation

Install it with yarn:

```
yarn add @arthurgeron/eslint-plugin-react-usememo --dev
```

or npm:

```
npm install @arthurgeron/eslint-plugin-react-usememo --save-dev
```

## Compatibility

This plugin targets ESLint v9+ (flat config). ESLint v8 is no longer supported. The package exposes named exports only.

### ESLint v9 Configuration (eslint.config.js)

#### Option 1: Use the plugin directly

```js
import { flatConfig } from "@arthurgeron/eslint-plugin-react-usememo";

export default [
  {
    files: ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"],
    languageOptions: {
      ecmaVersion: 2020,
      sourceType: "module",
      parserOptions: {
        ecmaFeatures: {
          jsx: true,
        },
      },
    },
    plugins: {
      "@arthurgeron/react-usememo": flatConfig,
    },
    rules: {
      "@arthurgeron/react-usememo/require-usememo": "error",
      "@arthurgeron/react-usememo/require-memo": "error",
      "@arthurgeron/react-usememo/require-usememo-children": "error",
    },
  },
];
```

#### Option 2: Use the recommended config

```js
import { flatConfig } from "@arthurgeron/eslint-plugin-react-usememo";

export default [
  flatConfig.configs.recommended,
];
```

#### Option 3: CommonJS syntax

```js
const { flatConfig } = require("@arthurgeron/eslint-plugin-react-usememo");

module.exports = [
  {
    plugins: {
      "@arthurgeron/react-usememo": flatConfig,
    },
    rules: {
      "@arthurgeron/react-usememo/require-usememo": "error",
      "@arthurgeron/react-usememo/require-memo": "error",
      "@arthurgeron/react-usememo/require-usememo-children": "error",
    },
  },
];
```

For migration guidance, please refer to our [ESLint v9 Migration Guide](https://github.com/arthurgeron/eslint-plugin-react-usememo/blob/main/docs/rules/eslint-v9-migration-guide.md).

## Examples

For a working example of ESLint v9 (flat config), please check the [examples directory](https://github.com/arthurgeron/eslint-plugin-react-usememo/tree/main/examples).

## Rule #1: `require-usememo` **_(recommended)_**

This rule requires complex values (objects, arrays, functions, and JSX) that get passed props or referenced as a hook dependency to be wrapped in useMemo() or useCallback().

One of the great features of this rule is its amazing autofix functionality. It intelligently wraps necessary components with useMemo() or useCallback(), making your code more efficient and saving you valuable time.

For detailed examples, options available for this rule, and information about the autofix functionality, please refer to our [rules documentation](https://github.com/arthurgeron/eslint-plugin-react-usememo/blob/main/docs/rules/require-usememo.md).

## Rule #2: `require-memo`

This rule requires all function components to be wrapped in `React.memo()`.

For detailed examples and usage of this rule, please refer to our [rules documentation](https://github.com/arthurgeron/eslint-plugin-react-usememo/blob/main/docs/rules/require-memo.md)

## Rule #3: `require-usememo-children`

This rule requires complex values (objects, arrays, functions, and JSX) that get passed as children to be wrapped in `useMemo()` or `useCallback()`.

For detailed examples and options available for this rule, please refer to our [rules documentation](https://github.com/arthurgeron/eslint-plugin-react-usememo/blob/main/docs/rules/require-usememo-children.md).

## Contributing

This project uses **Yarn** as its package manager. A `preinstall` script will reject `npm install` to keep the lockfile consistent — please use `yarn install` when working locally.

## Conclusion

By efficiently using `useMemo`, `useCallback`, and `React.memo()`, we can optimize our React and React Native applications. It allows us to control the re-calculation and re-rendering of components, offering better scalability and performance.

---
_Source: https://npm.io/package/@arthurgeron/eslint-plugin-react-usememo · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
