Render Phase: Pure Calculation
What you'll learn: How React calls your component functions during the render phase to compute what the UI should look like, without touching the DOM or triggering side effects.
The Calculation Step
Remember the three phases of React updates you just learned? The render phase is the first phase—it's when React calls your component functions to figure out what needs to be on screen.
Think of it like a calculator: you punch in numbers and operations, and it calculates the answer without changing anything in the world. It's pure math. Similarly, during the render phase, React is purely calculating what the next UI tree should be—no DOM changes, no network requests, no timers.
What "Pure Calculation" Means
When React calls your component function during rendering, it expects it to behave like a pure function:
- Same inputs → same output: Given the same props and state, your component should return the same JSX
- No side effects: Don't modify variables outside the function, don't call
fetch(), don't set timers, don't manipulate the DOM - No surprises: Just calculate and return JSX based on current props and state
React might call your component multiple times (remember Strict Mode's double-render?), or skip calling it altogether if nothing changed. Your component must be okay with that—it's just a calculation.
Why This Matters
By keeping rendering pure, React can:
- Call components as many times as needed without breaking things
- Optimize by skipping renders when possible
- Run rendering on background threads (future React features)
- Confidently batch multiple updates together
Key Takeaway: The render phase is React's pure calculation step—your components read props and state, compute JSX, and return it without side effects or DOM changes. All the "doing stuff" happens later in the commit phase.