Render vs Commit
Render phase computes Virtual DOM diffs without side effects; Commit phase applies changes to the real DOM synchronously.
Mental Model
"The Architect vs The Builder: The architect drafts blueprints in their office (Render Phase); the construction crew pours concrete on site (Commit Phase)."
Interactive Engine Walkthrough
Reference Code Snippet
1// Phase 1: Render (Pure)
2// React calls your component to see what it wants to render.
3function App() {
4 return <h1>Blueprint</h1>;
5}
6
7// Phase 2: Commit (Side Effects)
8// React applies changes to the actual DOM.- 01.Render Phase: Calls component functions, evaluates JSX, and computes diffs. Can be paused/restarted by React.
- 02.Commit Phase: Fast synchronous phase where React updates native DOM nodes and refs.
- 03.Side effects (HTTP requests, timers, DOM mutations) must NEVER happen in the render phase.
01. The Render Phase
In this phase, React walks down the component tree and determines what has changed. It is **pure and interruptible**. React can pause this work, throw it away, or restart it without the user ever seeing a half-finished UI. No DOM changes happen here.
Phase Invariants
02. The Commit Phase
Once React has the new tree ready, it enters the Commit phase. This is **synchronous and non-interruptible**. React applies all changes to the real DOM in one go. After this, it runs `useLayoutEffect` (synchronously) and `useEffect` (asynchronously).
Expert Rule
"Because the Render phase can be called multiple times before a commit, your component body must be **pure**. Never perform side effects (like API calls or logging) directly in the function body—save them for useEffect or event handlers."