Chapter 3. The Virtual DOM
In this chapter, we’ll dive deep into the concept of virtual DOM, sometimes called vDOM, and its significance in React. We’ll also explore how React uses the virtual DOM to make web development easier and more efficient.
As web applications become more complex, it becomes increasingly difficult to manage the “real DOM,” which is a complex and error-prone process as we’ll see soon enough, and as we crudely covered in Chapter 1. React’s virtual DOM provides a solution to this problem.
Throughout this chapter, we’ll explore the workings of React’s virtual DOM, its advantages over the real DOM, and how it is implemented. We’ll also cover how React optimizes performance around the real DOM using the virtual DOM and how it all fits together.
Through a series of code examples and detailed explanations, we’ll understand the virtual DOM’s role in React and how to take advantage of its benefits to create robust and efficient web applications. Let’s get started!
An Intro to the Virtual DOM
The virtual DOM, like the DOM, is an HTML document modeled as a
JavaScript object: this is literally what Document Object Model (DOM)
means. The DOM itself is the browser runtime’s model of the document.
The virtual DOM is a lightweight copy of this, with the key difference
that while the real DOM is made up of Node
objects, the virtual DOM is
made up of plain JS objects that act as descriptions. It allows web developers to create user interfaces in a more efficient and performant ...
Get Fluent React now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.