Featured

React Performance Optimization Techniques

T
Team
·11 min read
#react#performance#optimization#memo#code-splitting#core web vitals

React Performance Optimization Techniques


React can feel slow when components re-render too often or when the bundle is too large. This guide walks through performance optimization from basics to advanced patterns.


Beginner: When to Optimize


Don’t optimize too early. First measure: use React DevTools Profiler and Chrome Lighthouse. Look for:


  • Excessive re-renders – Components updating when their props/state didn’t change
  • Large initial JS – Slow First Contentful Paint (FCP) and Time to Interactive (TTI)
  • Heavy lists – Hundreds of DOM nodes causing layout thrash

  • Rule of thumb: Optimize when you have data (e.g. profiler shows a component taking >16ms per frame).


    Intermediate: Reducing Re-renders


    React.memo


    Prevent re-renders when props are referentially equal:


    javascript
    1const ExpensiveList = React.memo(({ items }) => {
    2 return items.map(item => <Item key={item.id} item={item} />);
    3});

    useMemo and useCallback


  • useMemo – Cache expensive computations so they only run when dependencies change.
  • useCallback – Stable function references so children using `React.memo` don’t re-render unnecessarily.

  • javascript
    1const sorted = useMemo(() => items.slice().sort(byDate), [items, byDate]);
    2const onSelect = useCallback((id) => setSelected(id), []);

    Code-splitting and lazy loading


    Split routes or heavy components so they load on demand:


    javascript
    1const HeavyChart = React.lazy(() => import('./HeavyChart'));
    2// In render:
    3<Suspense fallback={<Spinner />}><HeavyChart /></Suspense>

    Advanced: Lists and Virtualization


    Rendering thousands of rows kills performance. Use virtualization (e.g. react-window, @tanstack/react-virtual) so only visible rows are in the DOM.


  • Windowing – Render a small window of items; scroll position determines which items mount.
  • Keys – Always use stable, unique keys (e.g. `id`) to avoid reconciliation cost.

  • Expert: Bundle and Runtime


  • Bundle analysis – `next/bundle-analyzer` or `webpack-bundle-analyzer` to find large dependencies; replace or dynamic-import where possible.
  • Images – Use Next.js `Image` or lazy loading; prefer WebP; set dimensions to avoid CLS.
  • Core Web Vitals – Optimize LCP (hero image, fonts), FID/INP (less main-thread work), CLS (reserve space for images/ads).

  • For API payloads and configs used in React state, validate and format with our [JSON Formatter](/tools/json-formatter/) to keep data handling predictable and debuggable.


    Related tools

    Try these free developer tools from Codev Nexus.

    Enjoyed this article?

    Support our work and help us create more free content for developers.

    Stay Updated

    Get the latest articles and updates delivered to your inbox.

    React Performance Optimization Techniques - Codev Nexus | codev nexus