New
Introducing React Doctor for Enterprise

react-hooks-js/use-memo

Validates usage of the useMemo() hook against common mistakes. See [`useMemo()` docs](https://react.dev/reference/react/useMemo) for more information.

Validation prompt

Use this to decide whether a fired diagnostic is real or a false positive.

Fires on a useMemo whose callback has no return statement (it falls through and the memo's value is undefined). The cached value is therefore always undefined, making the hook useless and almost certainly indicating the wrong hook was chosen. False positive: a deliberately-empty stub left during refactoring — but the right fix is still to remove or repurpose it.

Fix prompt

Use this once validation confirms the diagnostic is real.

Add an explicit return for the computed value: useMemo(() => data.map(transform), [data]). If the body is purely side effects (analytics, logging, DOM writes), switch to useEffect for synchronization-style work or move the call into the event handler that triggers it. useMemo is for caching expensive computations, not for running code on dep change. See https://react.dev/reference/eslint-plugin-react-hooks/lints/use-memo

More React Compiler rules from the rules reference:

  • react-hooks-js/void-use-memo: Validates that useMemos always return a value and that the result of the useMemo is used by the component/hook. See [`useMemo()` docs](https://react.dev/reference/react/useMemo) for more information.
  • react-hooks-js/component-hook-factories: Deprecated: this rule has been removed in 7.1.0.
  • react-hooks-js/error-boundaries: Validates usage of error boundaries instead of try/catch for errors in child components
  • react-hooks-js/globals: Validates against assignment/mutation of globals during render, part of ensuring that [side effects must render outside of render](https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render)
  • react-hooks-js/hooks: Validates the rules of hooks