What Happens During the Render Phase
What you'll learn: How React calls your component functions to figure out what the UI should look like.
The Core Idea
When React needs to update the screen, it doesn't immediately touch the DOM. Instead, it first goes through a "render phase" where it calls your component functions to produce a blueprint of what the UI should be.
Think of it like an architect creating detailed drawings before construction begins. The render phase is React sketching out the plan—no actual building (DOM changes) happens yet.
What Actually Happens
During the render phase, React:
- Calls your component function (like
function Counter() { ... }) - Executes all your JSX and any hooks like
useStateoruseRef - Produces a tree of React elements—lightweight JavaScript objects describing what should appear on screen
- Compares this new tree to the previous one to figure out what changed
This tree is essentially a description: "Here's a <div> with a <button> inside that says 'Count: 5'."
Pure Calculation
The render phase is pure calculation—no side effects should happen here. React might call your component multiple times (or pause and resume) as an optimization, so you can't rely on:
- Direct DOM manipulation
- Network requests
- Setting timers
That's why those operations belong in useEffect, which runs after the render phase completes.
The Result
After the render phase finishes, React has a complete picture of what the UI should look like. It then moves to the commit phase (covered next) where it actually applies those changes to the real DOM.
Key Takeaway: The render phase calls your component functions to build a React element tree describing the desired UI, but doesn't touch the DOM yet—that's a pure calculation step.