Skip to content
Getting StartedChapter 5 / 37Intermediate5 min read

How React Renders

Learn how React rendering works with the virtual DOM, the trigger, render and commit phases, when a re-render happens, and what reconciliation is.

On this page

1. What is React rendering?

Rendering does not mean the DOM changed right away. React first builds a description of the new UI in memory (a tree of React elements). This in-memory tree is commonly called the virtual DOM. Then React compares the old and new trees and makes only the necessary DOM changes.

2. Why does it matter?

Touching the real DOM again and again is expensive. If the whole page were rebuilt on every small change, the app would be slow and would lose input focus or scroll position.

Rebuilding the whole DOMReact's way
Every element is new on each changeOnly the changed nodes are updated
Input focus and scroll resetWhat did not change stays as it is
The developer manages the DOMThe developer only changes state, React does the rest
Many updates mean many DOM writesMany state updates are batched into one commit

3. Where does it help?

This understanding helps wherever a React app is slow or behaves strangely:

SituationHow understanding rendering helps
PerformanceYou can tell which components re-render for no reason
State resetYou understand when state is kept and when it is lost
ListsYou understand the role of key
DebuggingThe React DevTools Profiler report becomes easy to read
InterviewsVirtual DOM and reconciliation are common questions

4. How does it work?

Every screen update in React happens in three steps:

Trigger, render, commit
Trigger: the first createRoot render, or a state update
Render: React calls the component functions
A new element tree is created
Reconciliation: React finds the difference between the old and new trees
Commit: only the necessary DOM changes are applied
The browser paints the screen

When does a re-render happen?

ReasonDetail
Its own state changedA setter like setCount was called with a new value
The parent re-renderedWhen a parent renders, all its children render too by default
A context value changedThe component that uses that context

Changing props is not a trigger by itself. Props change when the parent re-renders.

Two principles of reconciliation

PrincipleMeaning
Same position, same typeReact reuses the element and the state is kept
The type changedReact removes the old part and builds a new one, and the state is lost

In lists, React uses the key to recognize which item is which.

5. Code example

jsx
import { useState } from "react";

function Child() {
  console.log("Child rendered");
  return <p>I am the child</p>;
}

export default function Counter() {
  const [count, setCount] = useState(0);
  console.log("Counter rendered:", count);

  function handleClick() {
    setCount((c) => c + 1);
    setCount((c) => c + 1);
  }

  return (
    <div>
      <h2>Count: {count}</h2>
      <button onClick={handleClick}>+2</button>
      <Child />
    </div>
  );
}

How does the code work?

ItemMeaning
First loadBoth Counter and Child render
Button clicksetCount triggers a re-render
Two setCount callsThey are batched into one re-render, and count goes up by 2
Child logChild renders along with its parent
In the DOMOnly the text of the h2 changes, the p and button stay the same
StrictModeIn development, render may run twice, so the log can appear doubled

If you use the React Compiler with React 19, it memoizes components automatically, so components like Child avoid useless re-renders. Details are in React Compiler.

Interview tip

"Does a re-render mean a DOM update?" No. A re-render is only the component function running again. The DOM changes only when reconciliation finds a difference. That is why not every re-render is expensive.

6. Common mistakes

Mistake: Always treating a re-render as a problem

Why? Most re-renders are fast and do not even touch the DOM.

Better: Measure first with the React DevTools Profiler, then optimize only the slow parts.

Mistake: Doing side effects during render

Why? Render should be pure. Fetching or changing the DOM during render causes double calls and bugs.

Better: Put side effects in event handlers, or in useEffect if needed.

Mistake: Expecting the new value right after a state update

Why? setCount sets the value for the next render, and inside the same function count stays the old value.

Better: If you need the new value, use an updater function or keep the calculated value in a variable.

Mistake: Using the index as the key in a list whose order changes

Why? On reorder or delete, React reuses the state of the wrong item.

Better: Use each item's stable unique id as the key.

7. What to learn before and after

Final quick revision

PointDetail
RenderThe component function being called
Three stepsTrigger, render, commit
Virtual DOMA tree of React elements in memory
ReconciliationThe difference between the old and new trees
Re-render triggersState, parent render, context
BatchingMany state updates in one re-render