πŸŽ‰ 75% of content is free forever β€” Unlock Premium from $10/mo β†’
CW
NEWSLIVESearch All Content
πŸ’Ό Servicesℹ️ Aboutβœ‰οΈ ContactView Pricing Plansfrom $10

React Performance: Finding and Fixing Re-renders

React PerformanceOptimization🟒 Free Lesson

What You'll Learn

  • 1Identify the three events that cause a component to render again
  • 2Use the React DevTools profiler to name the component that started a render storm
  • 3Combine memo, useCallback and useMemo so that a memoized child actually skips work
  • 4Choose between memoization, code splitting, and virtualization for a slow screen

Measure before you touch a memo

Performance work has a reliable failure mode: sprinkling memo across a codebase, seeing no improvement, and concluding that React is slow. Almost every slow React screen is slow for one of three reasons, and each has a different fix. A component re-renders far more often than it should; a component does expensive work on every render; or the browser is laying out and painting far too much markup at once.

The React DevTools Profiler answers the first question directly. Record a interaction, and the flame chart shows which component committed, how long it took, and which component above it rendered for the first time. That second column matters more than the durations, because the culprit is usually a parent re-rendering with unchanged props rather than the child doing anything wrong. Optimise the parent, and the children stop being part of the problem.

The three triggers, and what they are not

TriggerExampleTypical fix
State in the component changesA text field updates its own valueNone needed, this is the point
A parent re-renders with new propsA new object or function passed every renderStabilise the prop or memoise the child
A context value the component reads changesTheme switch or session changeSplit context, or consume a narrower slice
The parent re-renders with identical propsAn ancestor's unrelated state changedReact.memo on the child, after confirming props are stable

That last row is where the confusion lives. React re-renders every child of a re-rendering parent unless the child is wrapped in memo and its props compare equal. Object.is is the default comparison, so an inline object, array, or arrow function is always unequal, and the memo wrapper becomes pure overhead.

Stabilising props so memo can work

A memoized child only skips rendering when the parent hands it stable references. The pair below shows the shape that makes memo effective, and the mistake that quietly defeats it.

import { memo, useCallback, useMemo, useState } from 'react';

const RowList = memo(function RowList({ rows, onActivate }) {
  console.log('RowList committed');
  return (
    <ul>
      {rows.map((row) => (
        <li key={row.id}>
          <button type="button" onClick={() => onActivate(row.id)}>
            {row.label}
          </button>
        </li>
      ))}
    </ul>
  );
});

export function Dashboard({ allRows }) {
  const [query, setQuery] = useState('');

  const rows = useMemo(
    () => allRows.filter((r) => r.label.toLowerCase().includes(query.toLowerCase())),
    [allRows, query]
  );

  const onActivate = useCallback((id) => {
    console.log('activate', id);
  }, []);

  return (
    <div>
      <input value={query} onChange={(e) => setQuery(e.target.value)} />
      <RowList rows={rows} onActivate={onActivate} />
    </div>
  );
}

Three things line up here. The filtered array is memoised so it keeps referential identity while the input is untouched, the handler is wrapped in useCallback so it survives across renders, and the list is wrapped in memo so it compares those references. Remove any one of the three and the commit log fills with entries again.

Expensive calculations belong in useMemo

useMemo exists to avoid repeating work whose inputs have not changed, not to protect identity in general. Sorting a hundred thousand rows, parsing a large document, or building a search index are all good candidates. Wrapping a two-element array concatenation is not.

function buildSummary(orders) {
  const byRegion = new Map();
  for (const order of orders) {
    let bucket = byRegion.get(order.region);
    if (!bucket) {
      bucket = { region: order.region, total: 0, count: 0 };
      byRegion.set(order.region, bucket);
    }
    bucket.total += order.total;
    bucket.count += 1;
  }
  return [...byRegion.values()].sort((a, b) => b.total - a.total);
}

function OrderReport({ orders }) {
  const summary = useMemo(() => buildSummary(orders), [orders]);
  const [page, setPage] = useState(0);

  return (
    <section>
      <SummaryTable rows={summary.slice(page * 10, page * 10 + 10)} />
      <button type="button" onClick={() => setPage((p) => p + 1)}>Next page</button>
    </section>
  );
}

Because the summary depends only on orders, flipping pages does not recompute it. That is the right trade: a few bytes of memory to protect a loop that takes tens of milliseconds.

A useful discipline is to put a number on the work before you memoise it. A console.time around a slow transformation, or a few rows in the React profiler showing a consistent duration, turns the decision into arithmetic rather than superstition. If the calculation takes half a millisecond and runs on a component that renders twice a session, the memo buys nothing and costs a closure and a dependency array forever. If it takes forty milliseconds on every keystroke, the same wrapper is an obvious win. The profiler answers whether a component renders too often; the stopwatch answers whether the work inside it matters. You need both answers before optimising, and most codebases have plenty of the first answer with none of the second.

Splitting the bundle so the first paint is cheap

Rendering cost and download cost both show up as slowness, and memoisation does nothing for the second. React.lazy gives each component its own chunk, and Suspense supplies the placeholder while it loads.

const AdminPanel = lazy(() => import('./AdminPanel'));
const ChartWorkspace = lazy(() => import('./ChartWorkspace'));

function Workspace({ mode }) {
  return (
    <Suspense fallback={<p>Loading workspace…</p>}>
      {mode === 'admin' ? <AdminPanel /> : <ChartWorkspace />}
    </Suspense>
  );
}

Split at genuine boundaries rather than at every component. Feature panels, editor surfaces, and anything behind an admin toggle are good seams; small presentational pieces are not, because the request overhead outweighs the bytes saved.

Cost that lives outside React's commit

The profiler only measures the commit phase. A component can render in two milliseconds and still produce a slow page if the markup it commits forces the browser into expensive work afterwards. Deeply nested selectors, animations driven through width or top, table layouts with automatic column sizing, and enormous runs of static rows all land in the layout, paint, and composite phases that React never reports.

The tells are different from React tells. Long tasks in the performance tab with no corresponding slow commit point at style and layout work. A janky scroll with a clean React profiler almost always means too much markup or an animation running on the main thread. The fixes are equally unglamorous: animate transform and opacity instead of layout properties, flatten the tree, replace table layout with grid, and virtualize anything with more rows than a screenful.

Third-party scripts belong in this conversation as well. Analytics bundles, chat widgets, and experiment tooling frequently dominate the main thread on mid-range hardware while the application code looks healthy in isolation. Profile on a throttled CPU so a fast laptop does not hide the problem, and defer anything that is not required for the first paint.

Long lists: virtualise before you memoise

A thousand rows each take a few milliseconds to render, which still adds up to seconds of work and a huge layout tree. Virtualization keeps only the visible window mounted and recycles the rest. The trade-offs are real: scroll height must be estimated, focus and accessibility need care, and measurement of row height requires either fixed heights or a measuring pass. For genuinely large collections, that cost is far smaller than rendering everything, and it composes with memoised rows rather than replacing them.

πŸ’‘The one-minute profiling routine

Record the interaction in the React DevTools Profiler, sort by the worst commit, then walk up the tree from the heaviest component until you find a parent that committed with unchanged props. Fix that parent first. Only after the commit count drops should you reach for useMemo, and only if the profiler still shows a hot function inside a component that now renders rarely.

Common Mistakes

Wrapping every component in React.memo without checking whether props are stable

Fix: Profile first, then memoise the few children that genuinely receive stable references

Creating inline objects, arrays or handlers for a memoised child on every render

Fix: Use useMemo for data and useCallback for handlers, or move creation inside the child

Memoising cheap work and paying the bookkeeping cost forever

Fix: Reserve memoization for calculations measured in milliseconds and inputs that rarely change

Rendering a virtualised list with unstable keys so rows remount while scrolling

Fix: Give every row a durable id so React can reuse the mounted instances

Best Practices

  • Keep the React DevTools Profiler in your workflow and record before editing
  • Log commit counts in development to confirm a memoisation actually reduced renders
  • Split bundles at feature boundaries and keep shared primitives in the initial chunk
  • Prefer fewer, larger memoised surfaces over dozens of tiny ones
  • Measure on a throttled CPU profile so desktop hardware does not hide real costs

Key Takeaways

  • A component renders when its own state changes, when a parent re-renders, or when a context value it reads changes
  • React.memo only helps when the parent passes references that compare equal with Object.is
  • useMemo protects both time and identity; useCallback exists mainly so memoised children can compare equal
  • Code splitting reduces first-load cost, which no amount of render optimisation can address
  • Virtualize very long lists before optimising individual rows
CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-12

β€”
β˜†β˜†β˜†β˜†β˜†
0 ratings

Rate & Feedback

Need Expert React Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement