How React Renders: Trigger, Render, Commit and Re-renders
Learn the three steps of a React update: trigger, render and commit. Understand re-renders, pure rendering, batching and double renders in StrictMode.
What you will learn
The word render is used a lot in React, and it often confuses beginners. Does it mean “draw on the screen”? Not exactly. In this lesson you will learn the three steps of every update (trigger, render, commit), what makes a component re-render, why re-rendering is not the same as updating the page, why your components must be pure, and why you sometimes see things run twice in development.
You should know useState and have read how React works behind the scenes.
The restaurant analogy
Think of a restaurant:
- Trigger: a customer places an order.
- Render: the kitchen prepares the dish, following the recipe.
- Commit: the waiter puts the dish on the customer’s table.
React works the same way. Every time something appears or changes on screen, React goes through exactly these three steps.
Trigger → Render → Commit
(why?) (what?) (put it on the page)
Step 1: trigger
A render is triggered in two ways:
- The initial render. When your app starts,
createRoot(...).render(<App />)triggers the very first render. - A state update. When you call a state setter such as
setCount, React schedules a re-render of that component.
That is all. A new render only starts because of one of those two things. (A change in props also leads to a re-render, but only because the parent re-rendered first, as you will see below.)
Step 2: render
“Rendering” means React calls your component functions to find out what should be on screen.
- On the initial render, React calls the root component (
App), then every component inside it, and so on down the tree. - On a re-render, React calls the component whose state changed, and then all the components inside it, to build a new description of the UI.
Importantly, rendering is just calling functions and getting elements back. At this stage nothing has changed on the page. It is like the kitchen preparing the dish: it is not at the table yet.
A parent’s re-render re-renders its children
Look at this example. We use console.log to see when each component is called:
import { useState } from 'react';
function Child({ label }) {
console.log("render Child " + label);
return <p>{label}</p>;
}
function Parent() {
console.log("render Parent");
const [count, setCount] = useState(0);
return (
<div>
<button onClick={() => setCount(count + 1)}>Count: {count}</button>
<Child label="static" />
</div>
);
}
When the page loads, the console shows:
render Parent
render Child static
Now click the button once. The console shows:
render Parent
render Child static
The state belongs to Parent, so Parent re-renders. But Child also renders again, even though its props (label="static") did not change. By default, when a component renders, all the components inside it render too.
This surprises many learners, but it is normal and usually very fast. React calls the functions, gets new elements, and compares them. It does not mean that the browser repaints everything, as the next step shows.
Step 3: commit
After rendering, React has a description of what the UI should look like. The commit step puts it on the page:
- On the initial render, React DOM creates all the DOM nodes and adds them to the page.
- On a re-render, React DOM compares the new description with the previous one and changes only the DOM nodes that are different.
A test with our example proves this. We watched the DOM with a MutationObserver while clicking the button. The only change in the page was the text inside the button (Count: 0 became Count: 1). The <p>static</p> element was not touched at all. It was the same DOM node before and after, even though Child ran again.
So:
Re-render (React calls functions) ≠ DOM update (the page changes)
React can call a hundred components and still change only one text in the page. After the commit, the browser does its own work: layout, paint and compositing, and you see the result.
Rendering must be pure
React may call your component at any time, and more than once, so it expects every component to be a pure function: for the same inputs (props, state, context), it always returns the same output, and it does nothing else while rendering.
A pure component:
- Only reads its props and state.
- Does not change anything that existed before it started rendering: no changing outside variables, no changing props or state directly.
- Does not do “side effects” while rendering: no fetching data, no timers, no changing the DOM, no logging to a server.
Here is a component that breaks the rule:
let guestCount = 0;
function Cup() {
guestCount = guestCount + 1; // changes a variable outside the component
return <p>Guest #{guestCount}</p>;
}
function App() {
return (
<>
<Cup />
<Cup />
<Cup />
</>
);
}
On a normal render this prints Guest #1, Guest #2, Guest #3. But the result depends on how many times React happened to call the function, and that is not something you control. The fix is to pass the data in as a prop:
function Cup({ guest }) {
return <p>Guest #{guest}</p>;
}
function App() {
return (
<>
<Cup guest={1} />
<Cup guest={2} />
<Cup guest={3} />
</>
);
}
Now the output depends only on the props. It is always Guest #1, Guest #2, Guest #3.
Where should side effects go? In event handlers (when the user does something) and, for things like data loading or timers, in Effects, which come in the next section of the course. Not in the render.
Local changes are fine. It is perfectly OK for a component to create and change variables inside itself during rendering, such as building an array before returning. What is not allowed is changing things that existed before this render started.
Why does it run twice? StrictMode
Remember <StrictMode> in main.jsx? In development, it renders every component twice on purpose. If your component is pure, the second render gives the same result and nobody notices. If it is impure, the double render exposes the bug.
Here is what the impure Cup example shows with StrictMode:
Guest #2
Guest #4
Guest #6
The numbers jump by two, because each Cup was called twice. The surprising output is a clue that something is wrong with the component. This is a feature, not a problem.
Also, a plain console.log inside a component prints twice per render in development for the same reason:
render Child strict
render Child strict
Do not panic and do not remove StrictMode. It does nothing in the production build. If you find the double logs annoying, remember that they are protecting you.
Batching: many updates, one render
What if you call the setter more than once in the same event handler?
function handleClick() {
setA(a + 1);
setB(b + 1);
setA((x) => x + 1);
}
React waits until the whole handler finishes, collects all the updates, and then renders once. This is called batching. In a test, a click that called three setters produced exactly one render pass, and the button showed a=2 b=1: the two updates to a were applied one after the other (0 → 1 → 2) with the updater function, and b became 1. Batching keeps your app fast and prevents the screen from showing half-finished states.
When does a state update not re-render?
If you set the state to the same value it already has, React compares the new and old value with Object.is. When they are the same, React does not need to update anything. In a test, clicking a button that ran setN(0) while n was already 0 produced no component renders at all. (React is allowed to call the component one more time before it decides to stop, so you should not rely on seeing zero logs. What is guaranteed is that nothing changes on the page.)
This is also why mutating an object does not work: profile.city = "Mumbai"; setProfile(profile) gives React the same object, so React sees “no change”, as you learned in the updating state lesson.
The whole story in one example
Click Add in the to-do app:
- Trigger:
addTodocallssetTodos([...]). React schedules a re-render ofApp. - Render: React calls
App, which callsTodoForm,TodoList(which callsTodoItemfor every todo) andTodoFooter. It gets a new description of the whole tree. - Commit: React DOM compares the new description with the old one. It sees one new
<li>and a changed count, so it creates that one list item and updates one text. All the other DOM nodes stay as they are. - The browser lays out and paints the changes.
Common mistakes
1. Thinking “render” means “draw on screen”. Render means calling your components. The screen only changes in the commit step, and only where needed.
2. Worrying that every re-render is slow. Calling components is cheap. Only optimise when you can measure a problem (a later lesson covers this).
3. Changing outside variables during rendering. Keep rendering pure. Use event handlers for changes.
4. Fetching data or starting timers directly in the component body. That is a side effect. Use an event handler or an Effect (covered next).
5. Removing StrictMode because logs appear twice. The double render is a development check, and it is helping you.
6. Calling the setter during rendering. setCount(count + 1) in the body causes an infinite loop. Call setters in handlers or Effects.
7. Expecting a state change to be visible immediately after calling the setter. The new value only appears in the next render (the snapshot idea from the updating state lesson).
8. Mutating state. React compares references, so mutated objects look “unchanged”.
Practice
-
Add
console.log("render Parent")andconsole.log("render Child")to a parent and a child, like in this lesson. Click a button in the parent three times. How many lines are printed for each component in total, including the first render? (Remember that in development withStrictModethe first render prints twice.) -
Predict, then check: In the example above, does the
Childrender again when you click the button inParent, even though its props did not change? Write down your answer, then test it. -
Use the browser’s Elements panel, select the
<p>of the child, and click the button in the parent several times. Does the<p>element change or flash? What does that tell you about re-rendering versus updating the DOM? -
Debug: This component gives different numbers each time. Rewrite it so it is pure.
let total = 0; function Item({ price }) { total = total + price; return <p>Running total: {total}</p>; } -
Create a button that calls
setA,setBandsetC(three different states) in one click. Log from the component body. How many renders do you see per click (ignoring theStrictModedoubling)? -
Debug: A learner starts a timer by writing
setInterval(...)directly inside the component body. What is wrong, and where could they start it instead? (You do not need the exact code yet. Name the place.) -
Create a component with
const [n, setN] = useState(0)and a buttononClick={() => setN(0)}. Click it several times, with aconsole.login the component. What do you notice? -
In your own words, explain the difference between render and commit, and say in which of the two steps the DOM is changed.
Recap
- Every update has three steps: trigger (initial render or state update), render (React calls your components), commit (React DOM updates the DOM).
- Rendering is calling functions. It does not change the page by itself.
- When a component renders, the components inside it render too, by default.
- In the commit step, React changes only the DOM nodes that differ. A re-render does not mean the whole page is redrawn.
- Components must be pure: same inputs, same output, and no side effects or outside changes during rendering.
- StrictMode renders twice in development to reveal impure code. It does nothing in production.
- Several state updates in one handler are batched into one render.
- Setting state to the same value does not change the page.
- Next you will learn how React compares the old and new trees to decide what to update.
Frequently asked questions
What is the difference between render and commit?
Render is the step where React calls your components and gets a description of the UI. Commit is the step where React DOM applies the needed changes to the real DOM. Rendering has no visible effect by itself. The screen changes only in the commit.
Why does my component log twice?
In development, StrictMode deliberately calls your component twice to help you find impure code. In the production build this does not happen. If the two calls give the same result, your component is pure and nothing is wrong.
Does a re-render mean the browser repaints the whole page?
No. A re-render means React called your functions again. React DOM then changes only the DOM nodes that are different, and the browser repaints only what is affected. Often a re-render changes a single text node.
Why do children re-render when the parent re-renders?
By default, rendering a component means rendering everything inside it. This is simple and usually fast. If it ever becomes a measured problem, there are tools to skip work for some components, which a later performance lesson explains.
What makes a component pure?
It always returns the same result for the same props, state and context, and it does not change anything outside itself while rendering. Side effects belong in event handlers or Effects, not in the component body.
What is batching?
React waits until an event handler has finished, collects all the state updates, and renders once. That avoids unnecessary renders and avoids showing half-updated screens.
See also: How React Works Behind the Scenes, useState in React, Updating Objects and Arrays in State, Choosing State Structure