Skip to content
Visual explainer 3h to learn 3 steps

Rendering & performance basics

Explain when components re-render and fix slow renders with the Profiler.

By Invicly Tech, , in Frontend with React & Next.js. About 11 minutes to read.

Topic 19 of 36

In short

A component re-renders when its state changes, its parent re-renders, or a context it uses changes. Most re-renders are cheap; measure with the React Profiler before reaching for memo, useMemo or useCallback.

Explained simply

Re-rendering means React calls your component function again to see what the screen should look like. It sounds expensive, but usually it is fast: React then compares the result with the last one and changes only the parts of the page that are different.

A component re-renders when its own state changes, when its parent re-renders, or when a context it reads changes. Note that a parent re-render re-renders all its children by default, even if their props did not change.

Most apps never need performance tuning. When something does feel slow, like typing lag in a big list, do not guess. Open the React DevTools Profiler, record the slow action, and see which components took the most time.

Then fix the real cause. Often moving state closer to where it is used is enough. Tools like memo, useMemo and useCallback help in specific cases, and the React Compiler can now add that memoization for you automatically.

Press Play on a diagram to walk through it one step at a time.

FlowFrom trigger to screen
  1. Step 1
    Trigger

    State, parent render or context change

  2. Step 2
    Render

    React calls components to produce new JSX

  3. Step 3
    Reconcile

    Compare new output with the previous tree

  4. Step 4
    Commit

    Apply only the real DOM changes

CompareMemoisation tools
memo
  • Wraps a component
  • Skips render if props are equal
  • Shallow prop comparison
useMemo
  • Caches a computed value
  • Recomputes when deps change
  • For expensive calculations
useCallback
  • Caches a function identity
  • Helps memo children skip renders
  • Useless without a memo consumer
MapWhy did this component re-render?
Component re-rendered
  • Its state changed
    • useState or useReducer setter
    • Fix: move state down
  • Its parent re-rendered
    • Default for all children
    • Fix: children prop or memo
  • A context it reads changed
    • Every consumer re-renders
    • Fix: split or memoize the value
  • Props changed identity
    • Inline objects or functions
    • Fix: useMemo or useCallback, or the compiler

In depth

Render is cheap, commit is targeted

React work has two phases. In the render phase, React calls component functions and builds a new tree of elements. In the commit phase, it applies only the differences to the DOM. A component can render many times without touching the DOM at all if its output is the same.

Renders become a problem in three situations: a component does expensive work in its body (sorting thousands of items, heavy formatting), a huge subtree re-renders on every keystroke, or the commit itself is big (thousands of DOM nodes). Each needs a different fix, which is why measuring comes first. Always judge speed on a production build: development builds include extra checks and Strict Mode double rendering, so they are much slower.

Profiling with React DevTools

Install the React Developer Tools browser extension and open the Profiler tab. Click record, do the slow action, and stop. The flame chart shows every component that rendered in each commit, colored by how long it took; the ranked chart sorts them by time. In the settings, turn on Record why each component rendered while profiling, and the Profiler tells you whether props, state, hooks or the parent caused each render.

The Components tab setting Highlight updates when components render flashes a border around everything that re-renders, which quickly shows a whole page re-rendering on each keystroke. For deeper analysis, the Chrome DevTools Performance panel shows long tasks, and React 19.2 adds React-specific tracks there for scheduler and component work.

CycleThe performance loop
  1. 1
    Notice

    Lag while typing, scrolling or clicking

  2. 2
    Record

    Profiler on a production-like build

  3. 3
    Find the cause

    Slowest component and why it rendered

  4. 4
    Fix one thing

    Move state, memo, defer, virtualize

  5. 5
    Measure again

    Keep the change only if it helped

  6. Back to step 1

Structural fixes before memoization

Two layout changes fix many slow renders without any memo. Move state down: if only a search input needs the query, keep the state in a small SearchBox component instead of the page, so typing re-renders SearchBox and not the whole page. Lift content up: if a component with changing state wraps expensive content, accept that content as children. The children elements were created by the parent, so they keep the same identity and React skips re-rendering them.

For urgent and non-urgent work, React has useTransition and useDeferredValue. Typing in an input is urgent; filtering a 5,000-row table can wait. useDeferredValue(query) gives a value that lags behind during fast typing, so React keeps the input responsive and renders the heavy list in the background. For very long lists, virtualization renders only the visible rows.

CompareMoving state down
State in Page
  • Page owns query
  • Each keystroke re-renders Page
  • Header, Chart and Table re-render too
  • Typing feels slow
State in SearchBox
  • SearchBox owns query
  • Each keystroke re-renders SearchBox
  • Header, Chart and Table are untouched
  • Typing feels instant

memo, useMemo and useCallback precisely

memo(Component) skips re-rendering when every prop is equal to last time by Object.is, a shallow comparison. Strings and numbers compare by value, but objects, arrays and functions compare by identity. So style={{ color: "red" }} or onClick={() => ...} written inline is new every render and defeats memo.

useMemo(() => compute(a, b), [a, b]) caches a calculated value until a or b change. Use it for expensive work, or to keep an object prop stable for a memo child. useCallback(fn, deps) is useMemo for functions: it keeps the same function identity, which only matters if a memo child or an effect depends on it. Each tool costs a little memory and comparison work, so wrapping everything can make code slower and harder to read.

  • memo: skip a child render when props are shallow-equal
  • useMemo: cache an expensive value
  • useCallback: keep a function identity stable
  • Inline objects and arrow functions break memo

The React Compiler

React Compiler is a build-time tool, stable since its 1.0 release in late 2025, that reads your components and inserts memoization automatically. It caches JSX, values and callbacks at a fine level, often better than hand-written useMemo and useCallback, and it does so only where it is safe.

It relies on your code following the rules of React: pure render, no mutating props or state, hooks at the top level. Code that breaks the rules is skipped, not miscompiled, and the eslint-plugin-react-hooks rules flag the problems. In Next.js 16 you install babel-plugin-react-compiler and set reactCompiler: true in next.config.ts; Vite projects add the Babel plugin. With the compiler on, manual memo is mostly unnecessary in new code, but profiling still matters: it cannot fix an oversized list or a slow algorithm.

Learn it in 3 short steps

About 1h each. Track them with a timer in your plan.

  1. 1
    Explain when components re-render~1h
  2. 2
    Profile renders with React DevTools~1h
  3. 3
    Apply memo, useMemo and useCallback carefully~1h

Key points

  • Rendering is not the same as updating the DOM; React commits only differences.
  • Profile first with React DevTools to find components that are actually slow.
  • memo only helps when props stay equal, so new objects each render defeat it.
  • Moving state down or passing children often fixes re-renders without memoisation.

Key terms

Tap a card to flip it. 0/5 known

Examples

Keeping typing fast with useDeferredValue

A product table with 5,000 rows filters on every keystroke and typing lags. Step 1: keep the input bound to query, which updates urgently. Step 2: create deferredQuery with useDeferredValue. Step 3: pass deferredQuery to the memoized table, so React can render it in the background and interrupt that work when a new key is pressed. Step 4: dim the table while it is stale.

tsx
import { memo, useDeferredValue, useState } from "react";

const ProductTable = memo(function ProductTable({ query }: { query: string }) {
  const rows = PRODUCTS.filter((p) => p.name.toLowerCase().includes(query.toLowerCase()));
  return <ul>{rows.map((p) => <li key={p.id}>{p.name}</li>)}</ul>;
});

export function Search() {
  const [query, setQuery] = useState("");
  const deferredQuery = useDeferredValue(query);
  const stale = query !== deferredQuery;
  return (<>
    <input value={query} onChange={(e) => setQuery(e.target.value)} aria-label="Search" />
    <div style={{ opacity: stale ? 0.6 : 1 }}><ProductTable query={deferredQuery} /></div>
  </>);
}
declare const PRODUCTS: { id: string; name: string }[];

Making memo actually work for list rows

The Profiler shows every TodoRow re-rendering when one todo toggles, even though TodoRow is wrapped in memo. Step 1: check why each rendered; the onToggle prop changed. Step 2: the parent creates onToggle inline, so it is a new function each render. Step 3: wrap it in useCallback and use the updater form so it does not depend on todos. Now only the changed row re-renders.

tsx
import { memo, useCallback, useState } from "react";

type Todo = { id: string; text: string; done: boolean };

const TodoRow = memo(function TodoRow({ todo, onToggle }: { todo: Todo; onToggle: (id: string) => void }) {
  return <li onClick={() => onToggle(todo.id)}>{todo.done ? "[x]" : "[ ]"} {todo.text}</li>;
});

export function TodoList({ initial }: { initial: Todo[] }) {
  const [todos, setTodos] = useState(initial);
  const onToggle = useCallback((id: string) => {
    setTodos((ts) => ts.map((t) => (t.id === id ? { ...t, done: !t.done } : t)));
  }, []);
  return <ul>{todos.map((t) => <TodoRow key={t.id} todo={t} onToggle={onToggle} />)}</ul>;
}

Quick reference

  • Re-render triggers: own state, parent render, or a context it reads
  • Profile a production build; development mode is much slower
  • Profiler setting: Record why each component rendered while profiling
  • Move state down, or pass expensive content as children, before using memo
  • memo compares props with Object.is; inline objects and functions break it
  • useDeferredValue keeps inputs responsive while heavy UI catches up
  • React Compiler auto-memoizes; Next.js 16: reactCompiler: true in next.config.ts
  • Thousands of rows: virtualize instead of memoizing each row

Common mistakes

  • Wrapping everything in useMemo and useCallback without measuring.
  • Passing inline objects to a memo component, so it re-renders anyway.

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1A parent re-renders. Its child's props did not change and the child is not wrapped in memo. Does the child re-render?

Question 2

2A memo child receives style={{ padding: 8 }} written inline. What happens?

Question 3

3Typing in a search box lags because a big table filters on each keystroke. Which hook is designed for this?

Question 4

4What does the React Compiler do?

0/4 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    Turn on Highlight updates in React DevTools, type into any input in your app, and list which components flash. Write down one that should not re-render.

  2. Exercise 2medium

    A Page holds a ticking clock in state (updates every second) and also renders an ExpensiveChart. Restructure it so the chart does not re-render every second, without using memo.

  3. Exercise 3hard

    A memo ProductCard gets product, onAdd and a formatted price object { amount, currency } built inline in the parent. Fix the parent so ProductCard only re-renders when its product changes.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

Should I wrap every component in React.memo?
No. memo adds comparison work and only helps when props stay equal and the render is costly. Measure first, or let the React Compiler handle it.
Do I still need useMemo and useCallback with the React Compiler?
Rarely in new code, because the compiler memoizes automatically. They are still useful as escape hatches, for example to keep an effect dependency stable in code the compiler skips.
Why is my React app slow only in development?
Development builds add warnings, extra checks and Strict Mode double rendering. Always measure performance on a production build.

Go deeper

ShareXLinkedInWhatsApp