Skip to content

Why React re-renders, and when it doesn’t

Working knowledgeUnder the hoodYou should know: basic React

You put a console.log in a component that takes no props, and it still logs on every click. Here is what decides which components React calls again, drawn one function call at a time.

01 A component with no props that keeps rendering

A small counter app. Each component logs when React calls it. Click the button once and watch the console.

App.jsx
import { useState } from 'react';
export default function App() {
return (
<>
<Header />
<Counter />
<Footer />
</>
);
}
function Counter() {
const [count, setCount] = useState(0);
console.log('Counter()');
return (
Text
Counter()
Display()
Hint()

Hint has no props and never changes, yet it logs on every click. Header and Footer never do. The reason is one rule, and once you see it the logs stop being a mystery.

02 What starts a render

A render is React calling your component function to find out what it should show now. Only a few things start one:

What starts a render, and what does not
EventRenders?Which components
A state setter or reducer dispatch with a new valueYesThe owner of that state, then everything below it
A context provider gets a new valueYesEvery component that reads that context
The parent renderedYesThe child, whether or not its props changed
Changing a local variable or a refNoNone: React is never told
Mutating a prop or state object in placeNoNone: React sees the same object

Notice that “its props changed” is not on the list. New props only reach a child because its parent rendered, and that parent render is what makes the child render.

03 One click, drawn

Here is the click from the first section, with the component tree on the left and React’s work on the right.

One click, from setState to the DOM
Step 1 of 7
component tree
App
Header
Counter
Display
Hint
Footer
what React did
Empty
  • update queued
  • rendered (called)
  • DOM changed
  • not called
  • untouched

The screen shows 0. Every component rendered once when the app started; nothing is happening now.

04 Rendering is not painting

A render does not touch the screen. React works in two phases: in the render phase it calls your functions and builds a new description of the UI; in the commit phase it applies only the differences to the DOM.

Render phase3 functions calledCheap for small components. Costly only when a render does heavy work or touches thousands of components.
Commit phase1 DOM node changedReact skips every DOM node whose output did not change, so Hint rendering again costs no DOM work.

So a re-render is usually not a problem in itself. It becomes one when a render is slow, or when it happens on every keystroke across a large tree.

05 Props alone do not re-render anything

React only hears about a change through a setter. Changing data any other way does nothing, even if that data is passed down as props.

Mutated: no render
const [user, setUser] = useState({ name: 'Ana' });
function rename() {
user.name = 'Bo';
setUser(user); // same object
}
Replaced: renders
const [user, setUser] = useState({ name: 'Ana' });
function rename() {
setUser({ ...user, name: 'Bo' });
}

React compares the new state with the old using Object.is. On the left it is the very same object, so React skips the update: the component and its children are not rendered again (React may still call the component itself once before it bails out). The screen keeps showing Ana.

06 Stopping the cascade

There are two common ways to keep a child out of its parent’s render. The first is memo, which skips the child when its props are equal to last time.

JavaScript
import { memo } from 'react';
const Hint = memo(function Hint() {
console.log('Hint()');
return <small>Click to count</small>;
});
The same click, with Hint wrapped in memo
component tree
App
Header
Countercount 1
Displayvalue 1
Hintmemo skip
Footer
  • rendered
  • not called

memo compares the new props with the old ones, key by key with Object.is. Hint has no props, so they are always equal and React reuses its last result.

The second needs no API at all: let the parent that does not change create the child, and pass it down as children. When Counter renders, children is the same element App made earlier, so React skips it.

JavaScript
// In App: <Counter><Hint /></Counter>
function Counter({ children }) {
const [count, setCount] = useState(0);
return (
<div>
<Display value={count} />
{children}
<button onClick={() => setCount(count + 1)}>+1</button>
</div>
);
}

memo compares props shallowly. An object, array or arrow function written inline in the parent is a new value on every render, so <Hint style={{ color: "gray" }} /> defeats memo every time. Move the value out of the component, or wrap it in useMemo or useCallback. If your project uses the React Compiler, it adds this memoisation for you.

07 Watch renders happen

  • A console.log at the top of a component logs once per render. In development under StrictMode, React calls each component twice per render to catch impure code, so expect doubled logs there (React 19 prints both; with the React DevTools extension installed, the second one is greyed out).
  • In the React DevTools browser extension, open Components, then the settings gear, and turn on Highlight updates when components render. Every rendered component flashes.
  • In the Profiler tab, record a click. With Record why each component rendered switched on in the settings, each bar says why: “Hook 1 changed”, “The parent component rendered”, or “Props changed”.

08 When re-renders surprise you

<Ctx.Provider value={{ user, setUser }}>A new context value each renderThe object literal is new every time the provider’s component renders, so every consumer renders too, even inside memo. Wrap the value in useMemo.
const [state, setState] = useState(...) // at the top of the appState kept too highTyping into a search box whose state lives in App renders the whole page per keystroke. Move the state down to the component that uses it.
<Row onSelect={() => pick(id)} />Inline functions break memoA memoised Row still renders, because the arrow function is a new prop each time. Use useCallback, or pass id and a stable handler.
items.push(x); setItems(items);Mutation looks like no changeSame array, so Object.is says equal and nothing renders. Build a new array: setItems([...items, x]).

09 Check yourself

Question

A parent calls setOpen(true) while open is already true. What happens to its children?

Question

Sidebar takes no props and is not wrapped in memo. Its parent Layout renders because its state changed. Does Sidebar render?

Question

Item is wrapped in memo and gets onClick={() => remove(id)}. Its parent renders. Does Item render?

10 Practise this

Was this tutorial useful?Your vote tells us what to improve next.
Spotted a mistake, or something unclear?