React Best Practices

Chapter 4 · Practice 2 of 5

Use useMemo and useCallback only as an escape hatch

From Performance and memoization

Why it matters

With React Compiler on, useMemo and useCallback become an escape hatch, not a habit.

SituationWhat to do
New code, compiler onWrite it without manual memoization and let the compiler decide
Need precise control, such as a stable effect dependencyKeep useMemo or useCallback there
Existing memoization, compiler just enabledLeave it in place, or test carefully before removing it
No compilerMemoize only after profiling shows a real cost

Removing existing memoization can change what the compiler outputs, which is why the React team advises caution.

Avoid

  • Wrapping every function in useCallback by habit
  • Removing existing memoization in bulk without tests