MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Virtual DOM and React Render Cycle Explained0%
Study Materials
React.js for BeginnersProgress 0%
1.1Why React and Single-Page Architecture1.2Setting Up Modern React with Vite1.3React Project Directory Structure and Entry Points1.4Virtual DOM and React Render Cycle Explained
HomeTutorialsReact.js for BeginnersVirtual DOM and React Render Cycle Explained
Understanding JSX Syntax and HTML Differences

Virtual DOM and React Render Cycle Explained

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

1. The Cost of Real DOM Manipulations

The browser's Document Object Model (DOM) is a tree-structured representation of HTML elements on the web page. While in-memory JavaScript operations are measured in nanoseconds, manipulating the real browser DOM is comparatively slow and computationally expensive.

Whenever you mutate a DOM node (e.g., modifying element.style.width or inserting a new <li>):

  1. 1
    The browser recalculates styles for all affected elements (Recalculate Style).
  2. 2
    It recomputes the exact physical geometry and position of every element on the screen (Layout / Reflow).
  3. 3
    It redraws the visual pixels on the screen layers (Repaint).
  4. 4
    It merges the layers to output the final display (Compositing).

Repeatedly running this layout-and-repaint pipeline for frequent UI updates causes dropped frames, noticeable stutter, and poor user experience.

1Real DOM Mutation Pipeline:
2[JavaScript Mutation] ──> [Style Recalculation] ──> [Reflow / Layout] ──> [Repaint] ──> [Compositing]
3 ▲
4 (Heavy GPU / CPU Cost)

2. What is the Virtual DOM?

The Virtual DOM (VDOM) is a lightweight, pure JavaScript object tree that mirrors the structure of the real browser DOM. Because it is a plain JavaScript object residing in memory, creating, cloning, and inspecting VDOM nodes is blazingly fast and never triggers browser reflows or repaints.

For example, this JSX element:

1<button className="btn-primary" onClick={handleClick}>
2 Save Changes
3</button>

Is represented under the hood as a lightweight Virtual DOM object similar to:

1{
2 type: 'button',
3 props: {
4 className: 'btn-primary',
5 onClick: handleClick,
6 children: 'Save Changes'
7 }
8}

3. The 3 Phases of the React Render Cycle

React manages UI updates through a disciplined three-phase cycle: Trigger, Render, and Commit.

1[1. Trigger] [2. Render Phase] [3. Commit Phase]
2User clicks button React executes component React applies calculated
3State variable changes ──> Generates new Virtual DOM ──> diff to real DOM
4 Diffs against previous VDOM Browser repaints UI

Phase 1: Triggering a Render

A render is triggered by two events:

  • Initial Render: When your application first loads via root.render(<App />).
  • State Re-render: When a component's state updater function is invoked (e.g., setCount(prev => prev + 1)) or its parent re-renders.

Phase 2: The Render Phase (Pure Computation)

During the render phase, React executes your component functions from the top down to construct the new Virtual DOM tree.

  • React compares the newly generated Virtual DOM tree against the previous Virtual DOM tree using its high-performance Reconciliation Algorithm (historically Fiber).
  • It calculates the absolute minimum set of real DOM operations required to reconcile the two trees (the "diff").
  • Crucial Rule: The render phase is pure computation; no changes are made to the real browser screen here.

Phase 3: The Commit Phase (DOM Mutation)

Once the diff is calculated, React enters the commit phase:

  • On initial render, React uses native methods (appendChild, insertBefore) to place all created DOM nodes into the container.
  • On subsequent state updates, React applies only the specific changes (e.g., modifying one text node's content or updating a single attribute) to the real DOM.
  • Once React completes mutating the real DOM, the browser paints the screen to reflect the new state.

4. Reconciliation and Keyed Diffing

To achieve $O(n)$ linear performance when diffing large element trees, React relies on two pragmatic heuristic assumptions:

  1. 1
    Different Element Types: Two elements of different types (e.g., changing from <div> to <section>) produce completely different trees. React unmounts the old element and mounts the new one from scratch.
  2. 2
    Element Keys in Lists: In dynamic lists, React uses the key prop to match elements between renders. This allows React to move, add, or delete specific items without re-creating unaffected sibling nodes.

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
Why is manipulating the real browser DOM directly considered computationally expensive?
Question 2
What is the Virtual DOM in React?
Question 3
Which sequence correctly represents the three stages of the React render cycle?
Question 4
During which phase of the React render cycle are actual mutations made to the browser's real DOM?
Question 5
What is the primary purpose of React's Reconciliation process?
Next Lesson

Understanding JSX Syntax and HTML Differences

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
React Project Directory Structure and Entry PointsUnderstanding JSX Syntax and HTML Differences

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master React.js for Beginners with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext