Why React re-renders, and when it doesn’t
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.
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:
| Event | Renders? | Which components |
|---|---|---|
| A state setter or reducer dispatch with a new value | Yes | The owner of that state, then everything below it |
| A context provider gets a new value | Yes | Every component that reads that context |
| The parent rendered | Yes | The child, whether or not its props changed |
| Changing a local variable or a ref | No | None: React is never told |
| Mutating a prop or state object in place | No | None: 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.
- 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.
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.
const [user, setUser] = useState({ name: 'Ana' });function rename() {user.name = 'Bo';setUser(user); // same object}
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.
- 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.
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.logat the top of a component logs once per render. In development underStrictMode, 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]).