React re-renders can slow down applications. Here's how to optimize with memoization.
Understanding Re-renders
React.memo Basics
useCallback for Functions
useMemo for Values
Common Patterns
Component Composition
Virtualization
Profiling Performance
When NOT to Memoize
Advanced Patterns
Best Practices
When to Use:
✓ Expensive computations
✓ Components with many children
✓ Callbacks passed to memoized children
✓ Context values
✓ Virtualized lists
When to Skip:
✓ Simple/cheap operations
✓ Props that always change
✓ Components that rarely re-render
✓ Small component trees
Debugging:
✓ Use React DevTools Profiler
✓ Add console.logs to track renders
✓ Use why-did-you-render in development
✓ Measure before optimizing
Patterns:
✓ Move state down
✓ Lift content up
✓ Split contexts
✓ Use refs for callbacks
Conclusion
React.memo, useMemo, and useCallback prevent unnecessary re-renders when used correctly. Profile first to identify actual performance issues, then apply memoization strategically. Over-optimization adds complexity without benefits. Focus on component composition patterns and virtualization for the biggest performance gains.