The Re-render Lifecycle Flow
You'll learn: How React processes a state update from the moment you call setState through to pixels appearing on screen.
When you call a state setter like setCount(5), React doesn't instantly change the DOM. Instead, it follows a precise four-step process that ensures updates are efficient and consistent.
The Four Phases
1. Schedule
React marks the component as "needs update" and adds it to a queue. Your setState call returns immediately—this is why state updates are asynchronous. The actual work happens later.
2. Render
React calls your component function again, this time with the new state value. Your function executes, JSX is evaluated, and React gets a fresh description of what the UI should look like. This is a pure calculation—no DOM changes happen yet.
3. Commit
React compares the new UI description with the old one (this comparison is called "reconciliation"). It figures out the minimal set of changes needed and applies them to the actual DOM. This phase is synchronous and very fast.
4. Browser Paint
The browser receives the DOM changes and repaints the pixels on screen. This is outside React's control—it's the browser's job.
Analogy
Think of redecorating a room:
- Schedule: You decide "I want blue walls"
- Render: You sketch what the room will look like in blue
- Commit: You compare your sketch to the current room and buy only the paint you need
- Browser Paint: You actually paint the walls
Key Takeaway: Every state update flows through schedule → render → commit → browser paint. React controls the first three phases; the browser handles the last one. This is why you can't read state immediately after calling setState—the render hasn't happened yet!