When Structural Changes Beat memo
You'll learn: When reorganizing your component tree is simpler and more effective than adding React.memo everywhere.
The Maintenance Cost Comparison
You've learned several techniques: React.memo, useCallback, composition patterns, and moving state down. But which approach should you reach for first?
The composition/structural approach wins on maintainability because it doesn't require you to think about referential stability at all. When you move state down or lift content up, you're working with React's natural re-render flow, not fighting it with optimization APIs.
The memo Maintenance Tax
Sprinkling React.memo throughout your tree creates an ongoing cost:
- You must ensure all callbacks are wrapped in
useCallback - You must ensure all object/array props are stable with
useMemo - You create dependency arrays that need maintenance
- New developers must understand the entire memoization strategy
- Bugs from stale closures become more likely
Think of it like this: memo is duct tape holding back re-renders. Restructuring components is fixing the plumbing so the leak doesn't happen.
When Structural Wins
If you can achieve the same performance by:
- Moving state closer to where it's used
- Splitting one component into two focused pieces
- Passing children as props to isolate updates
...then do that instead. Your code will be easier to understand, easier to modify, and won't break when someone forgets to memoize a callback.
When memo Still Wins
Sometimes you can't restructure (third-party components, complex shared state). In those cases, memo is the right tool. But treat it as a last resort after exploring compositional solutions.
Key Takeaway: Prefer restructuring your component tree over adding memo—it's simpler, more maintainable, and doesn't require orchestrating useCallback/useMemo dependencies across your codebase.