Course contentsShow
← React
Lesson 405 of 2,39612. Rendering and BatchingFree lesson

Rendering vs Committing: The Two-Phase Process

React splits updates into render (calculating changes) and commit (applying to DOM)—only commit touches the browser.

Rendering vs Committing: The Two-Phase Process

What you'll learn: React doesn't immediately touch the browser when you update state—it first calculates changes (render), then applies them (commit).

The Two-Phase Mental Model

When you call a state setter like setCount(5), React doesn't instantly manipulate the DOM. Instead, it performs work in two distinct phases:

  1. Render Phase: React calls your component function to figure out what should be on screen. It calculates the new virtual representation but doesn't touch the actual DOM yet.

  2. Commit Phase: React takes the calculated changes and applies them to the real browser DOM—this is when pixels actually change on screen.

Why This Matters

Think of it like planning a room makeover. First, you measure and sketch changes on paper (render phase)—you're not moving furniture yet. Only after planning do you actually rearrange the room (commit phase).

This separation is crucial because:

  • The render phase is pure calculation—your component function runs, React compares the new output to the previous one
  • Only the commit phase touches the browser—this is where performance matters most
  • React can optimize by batching multiple renders into one commit

What Happens in Each Phase

Render phase:

  • Component function executes
  • React builds a virtual tree of elements
  • No side effects should happen here

Commit phase:

  • React updates the actual DOM
  • Browser repaints the screen
  • Effects (like useEffect) run after commit completes

Key Takeaway: React separates the "thinking" phase (render) from the "doing" phase (commit)—only commit touches the browser, which is why rendering can be interrupted or batched without visible flicker.