Interview Q&A / React

BeginnerIn-depth4 min readUpdated 2 Oct 2026

What is the virtual DOM, and how does reconciliation work in React?

SHORT ANSWER

The virtual DOM is React's lightweight description of what the UI should look like, made of plain JavaScript objects. On each update React compares the new description with the previous one (reconciliation) and changes only the parts of the real DOM that differ.

Explain it simply

Imagine the class notice board. Every morning the class representative gets a fresh printed list of notices. Instead of tearing down the whole board and pinning everything again, they compare the new list with what is already on the board. One notice changed, one is new, one was removed. They swap just those three sheets.

React works the same way. Your components return JSX, which becomes a tree of plain JavaScript objects describing the UI. People call this the virtual DOM. The real DOM in the browser is the notice board. When state changes, React builds a new tree, compares it with the old one, and makes only the needed changes to the real DOM.

Updating the real DOM is not terribly slow by itself, but touching it more than necessary causes extra layout and paint work and loses things like focus and scroll position. The comparison step lets you write code as if you re-render everything, while React keeps the real changes small.

Example

jsx
function Counter() {
  const [count, setCount] = useState(0);
  return (
    <div className="card">
      <h2>Placement Tracker</h2>
      <p>Applications sent: {count}</p>
      <button onClick={() => setCount(count + 1)}>Add</button>
    </div>
  );
}

When you click the button, Counter runs again and returns a new tree. React compares it with the old tree. The div, h2 and button are the same. Only the text inside p changed from 0 to 1, so React updates just that text node.

How it works

Comparing two arbitrary trees perfectly is expensive, so React uses simple rules that work well in practice:

  1. Different element type means replace. If a <div> becomes a <section>, or <ProfileCard> becomes <LoginForm>, React removes the old subtree, including its state, and builds a new one.
  2. Same type means update. React keeps the same DOM node or component instance and updates only the changed attributes and props, then continues into the children.
  3. Keys identify list items. Among siblings, React matches children by key, so reordered items keep their state.

This happens in two phases. In the render phase React calls your components and works out what changed. In the commit phase it applies those changes to the real DOM and then runs effects. The render phase can be paused or interrupted for more urgent updates; the commit phase is applied in one go so users never see a half-updated screen.

Real-world use

  • Re-rendering a long list of products when a filter changes, while only touching the rows that changed.
  • Typing in a search box where the input keeps its focus while the results below update.
  • Understanding why a component's state resets: if its type or key changes, React treats it as a new component.

Common mistakes

  • Saying "the virtual DOM makes React faster than plain JavaScript". Carefully written direct DOM updates can be faster; the benefit is that you get reasonable performance while writing simpler, declarative code.
  • Defining a component inside another component. A new function is created on every render, so React sees a different type each time and resets its state.
  • Thinking a re-render always means the DOM changed. Many re-renders end with no DOM changes at all.

What to say in the interview

"The virtual DOM is the tree of JavaScript objects that React builds from my components' JSX. When state or props change, React re-renders to get a new tree and reconciles it with the previous one. It uses heuristics: a different element type replaces the subtree, the same type is updated in place, and keys match list items. Then in the commit phase it applies only the minimal changes to the real DOM. The point is not that it is magically fast, but that I can write declarative code and React handles efficient updates."

Follow-up questions

  • What is the difference between re-rendering and updating the DOM?
  • Why does changing a component's key reset its state?
  • What is React Fiber, and why can rendering be interrupted?

Go deeper

Read these once the basics above feel easy.

Fiber is the name of React's internal reconciliation engine. Each element in the tree becomes a unit of work called a fiber. Because work is split into small units, React can pause rendering to handle a more urgent update, such as typing, and then resume. Features like startTransition rely on this: they mark an update as less urgent so React can keep the screen responsive.

#virtual-dom#reconciliation#rendering

Related questions

Practise more React questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open React quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.