Explore advanced React optimisation techniques including React.memo, useMemo, useCallback, react-window virtual lists, and Profiler-driven debugging.
Why React Performance Matters
Large React applications accumulate unnecessary re-renders over time. A 200 ms interaction delay feels instant on localhost but catastrophic in production, especially on mid-range mobile devices.
The Golden Rule
Measure first. Optimise second. Open React DevTools Profiler and record a slow interaction. Look for components with long render times or high commit count before reaching for memo.
1. React.memo — Shallow Prop Equality
React.memo prevents re-render when props are shallowly equal. It has a small overhead — only apply it to components that render frequently with stable props.
2. useMemo — Expensive Computations
Use useMemo for transformations that are genuinely expensive (>1 ms). Avoid wrapping cheap calculations — the dependency comparison cost can exceed the computation cost.
3. useCallback — Stable Function References
Stable references prevent child memos from invalidating. Most useful when passing callbacks to memoised children or effect dependency arrays.
4. Virtual Lists with react-window
Render only visible rows for lists with 500+ items:
5. Code Splitting with next/dynamic
Route-level splitting happens automatically with the App Router. Component-level splitting is for client-heavy components loaded conditionally.