0
0
Reactframework~10 mins

ReactDOM render process - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - ReactDOM render process
Start ReactDOM.render()
Evaluate JSX -> Create React Elements
Build Virtual DOM Tree
Compare with Previous Virtual DOM?
Diff Virtual DOM
Update Real DOM
React Component Mounted
End
This flow shows how ReactDOM.render starts by creating React elements, builds a virtual DOM, compares it to the previous one, then updates or mounts the real DOM accordingly.
Execution Sample
React
import React from 'react';
import ReactDOM from 'react-dom/client';

const App = () => <h1>Hello!</h1>;

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);
This code creates a React root and renders a simple App component that displays 'Hello!'
Execution Table
StepActionEvaluationResult
1Call ReactDOM.createRootdocument.getElementById('root') foundRoot object created
2Call root.render(<App />)Evaluate <App /> JSXReact element: {type: 'h1', props: {children: 'Hello!'}}
3Build Virtual DOM treeVirtual DOM tree with one h1 nodeVirtual DOM ready
4Compare with previous Virtual DOMNo previous Virtual DOMMount new DOM
5Create real DOM node <h1>Create DOM elementDOM node <h1>Hello!</h1> created
6Insert DOM node into #rootAppend childDOM updated in browser
7Component mountedReact lifecycle completeUI visible with 'Hello!'
8EndRender process completeReactDOM.render finished
💡 Render process ends after mounting the initial DOM and completing component lifecycle
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 5Final
rootundefinedRoot object createdRoot object unchangedRoot object unchangedRoot object unchanged
elementundefinedReact element createdVirtual DOM tree builtVirtual DOM unchangedVirtual DOM unchanged
realDOMundefinedundefinedundefined<h1>Hello!</h1> node created<h1>Hello!</h1> node inserted
Key Moments - 3 Insights
Why does React build a Virtual DOM before updating the real DOM?
React builds a Virtual DOM to compare with the previous one (see step 4) so it only updates parts that changed, making updates faster and efficient.
What happens if there is no previous Virtual DOM?
If no previous Virtual DOM exists (step 4), React mounts the entire new DOM from scratch (step 5), as shown in the execution table.
When does the real DOM get updated during render?
The real DOM updates happen after React creates the DOM nodes (step 5) and inserts them into the page (step 6), making UI visible.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the React element created at step 2?
AA button element with label 'Click'
BA div element with no children
CAn h1 element with text 'Hello!'
DAn empty React fragment
💡 Hint
Check the 'Evaluation' column at step 2 in the execution table
At which step does React insert the real DOM node into the page?
AStep 5
BStep 6
CStep 3
DStep 7
💡 Hint
Look for the action describing 'Insert DOM node' in the execution table
If a previous Virtual DOM existed, what would React do differently at step 4?
ACompare Virtual DOMs and update only changed parts
BSkip comparing and mount new DOM anyway
CDelete the previous DOM and rebuild everything
DDo nothing and end render
💡 Hint
Step 4 shows the decision React makes based on previous Virtual DOM presence
Concept Snapshot
ReactDOM.render process:
1. Create React elements from JSX
2. Build Virtual DOM tree
3. Compare with previous Virtual DOM
4. Update or mount real DOM accordingly
5. Complete component lifecycle and show UI
Full Transcript
The ReactDOM render process starts when ReactDOM.createRoot is called with a DOM container. Then root.render is called with a React component. React evaluates the JSX to create React elements, which form a Virtual DOM tree. React compares this Virtual DOM with the previous one to find changes. If no previous Virtual DOM exists, React mounts the new DOM nodes directly. It creates real DOM elements and inserts them into the container. Finally, the component lifecycle completes and the UI becomes visible. This process optimizes updates by minimizing real DOM changes.