0
0
Reactframework~10 mins

Rendering elements in React - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Rendering elements
Start React Component
Evaluate JSX
Create React Element Objects
ReactDOM.render
Browser DOM Update
User Sees UI
React components run, JSX is turned into React elements, then React updates the browser DOM to show the UI.
Execution Sample
React
function Hello() {
  return <h1>Hello, world!</h1>;
}

ReactDOM.render(<Hello />, document.getElementById('root'));
This code defines a simple React component that renders a heading, then renders it inside the page.
Execution Table
StepActionEvaluationResult
1Call Hello()Return JSX <h1>Hello, world!</h1>JSX element object created
2ReactDOM.render calledReceives React element from Hello()Schedules DOM update
3React reconcilesCompares with previous DOM (none)Creates <h1> element in DOM
4Browser updates DOMAdds <h1>Hello, world!</h1> inside #rootUser sees heading on page
5No further updatesNo state or props changedRendering stops
💡 Rendering stops because no state or props changed to trigger update
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
React Elementnull{type: 'h1', props: {children: 'Hello, world!'}}Same element passed to ReactDOM.renderElement reconciled and DOM createdElement rendered in DOM
Key Moments - 2 Insights
Why does React create an object instead of directly creating DOM elements?
React first creates a React element object (see Step 1 in execution_table) to efficiently compare changes before updating the real DOM, improving performance.
What triggers React to update the DOM after initial render?
React updates the DOM only when state or props change. In this example, no changes occur after Step 4, so rendering stops (see exit_note).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is created at Step 1?
AA React element object representing <h1>Hello, world!</h1>
BA real DOM <h1> element
CA string 'Hello, world!'
DA function Hello()
💡 Hint
Check the 'Evaluation' and 'Result' columns at Step 1 in the execution_table
At which step does the browser DOM actually get updated?
AStep 1
BStep 2
CStep 4
DStep 3
💡 Hint
Look for 'Browser updates DOM' action in the execution_table
If the component had state that changed, what would happen after Step 5?
ANothing, rendering always stops at Step 5
BReact would re-run the component and update the DOM if needed
CThe browser would reload the page
DReact would throw an error
💡 Hint
Refer to the exit_note and key_moments about what triggers React updates
Concept Snapshot
React rendering flow:
1. Component function runs and returns JSX.
2. JSX compiles to React element objects.
3. ReactDOM.render schedules DOM updates.
4. React compares elements and updates browser DOM.
5. User sees UI changes.
Updates happen only on state/props changes.
Full Transcript
Rendering elements in React means running a component function that returns JSX. React turns this JSX into React element objects, which are lightweight descriptions of what the UI should look like. ReactDOM.render takes these elements and updates the browser's DOM to match. This process happens step-by-step: first creating the element object, then scheduling the DOM update, then React compares with the current DOM and applies changes, and finally the browser shows the updated UI. React only updates the DOM again if the component's state or props change, otherwise rendering stops after the initial update.