Chapter 4 · Practice 2 of 5
Use useMemo and useCallback only as an escape hatch
Why it matters
With React Compiler on, useMemo and useCallback become an escape hatch, not a habit.
| Situation | What to do |
|---|---|
| New code, compiler on | Write it without manual memoization and let the compiler decide |
| Need precise control, such as a stable effect dependency | Keep useMemo or useCallback there |
| Existing memoization, compiler just enabled | Leave it in place, or test carefully before removing it |
| No compiler | Memoize 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
useCallbackby habit - Removing existing memoization in bulk without tests