Course contentsShow
← React
Lesson 1509 of 2,39637. React 19 and BeyondFree lesson

Migration Strategy: Removing Manual Memoization

How to safely remove useMemo/useCallback when adopting the compiler without breaking behavior.

Migration Strategy: Removing Manual Memoization

You'll learn: How to safely transition from manual useMemo/useCallback to compiler-based optimization without breaking your app.

The Safe Migration Path

When adopting the React Compiler, you don't need to remove all your memoization at once. Think of it like removing training wheels from a bike—you want to ensure stability before letting go.

The compiler will work alongside your existing useMemo and useCallback calls. If you've already memoized something manually, the compiler won't double-wrap it. This means your first step is simple: turn on the compiler and change nothing.

Identifying What to Remove

After the compiler is running, look for:

  1. Simple calculations wrapped in useMemo—the compiler handles these automatically now
  2. Callback functions in useCallback that have no specific identity requirements
  3. Props passed to memoized children—the compiler optimizes the entire tree
// BEFORE (manual)
const filtered = useMemo(() => 
  items.filter(item => item.active), 
  [items]
);

// AFTER (compiler handles it)
const filtered = items.filter(item => item.active);

When to Keep Manual Memoization

Don't remove memoization if:

  • It's tied to specific library requirements (like dependency arrays in external hooks)
  • You're memoizing for referential equality that external code depends on
  • Performance profiling shows the compiler's version is slower (rare, but measure first)

Gradual Rollout Strategy

Remove memoization one component at a time, testing between changes. Start with leaf components (no children) and work upward through your tree.

Key Takeaway: The compiler coexists with manual memoization—enable it first, then gradually remove manual optimizations while measuring performance to ensure no regressions.