Course contentsShow
← React
Lesson 948 of 2,39624. React.memoFree lesson

When the Pattern Adds More Cost Than Value

Recognizing scenarios where memo + useCallback overhead exceeds re-render cost and simpler code wins.

When the Pattern Adds More Cost Than Value

What you'll learn: How to recognize when the overhead of memo + useCallback creates more problems than it solves.

The Optimization Trap

You've learned the parent-child memo + useCallback pattern: wrap your child in React.memo, wrap parent callbacks in useCallback, and watch re-renders disappear. But sometimes this "optimization" makes things worse.

The pattern adds three costs:

  1. Shallow comparison cost - React.memo must compare all props every time the parent renders
  2. Memoization bookkeeping - useCallback stores functions and checks dependencies
  3. Code complexity - More hooks, more mental overhead, harder to read

When your child component is cheap to render (just a few DOM elements, no loops, no heavy computation), these costs can exceed the render cost itself. You're paying for optimization machinery that saves nothing.

When Simpler Code Wins

If your component renders in microseconds, just let it re-render. A basic button component? A single <div> with text? The React reconciliation for these is incredibly fast. Adding memo + useCallback turns 3 lines of clean code into 10 lines of "optimized" code that's actually slower.

The rule of thumb: If you can't measure a performance problem with DevTools Profiler, don't add the optimization. Premature optimization creates maintenance burden without benefit.

Think of it like hiring a security guard to protect an empty box. The guard costs money and gets in your way, but there's nothing valuable to protect.

Key Takeaway: When render cost is negligible, the memo + useCallback pattern adds overhead without benefit—skip it and keep your code simple until profiling proves you need it.