DEV Community

Nazmul Islam Nahid
Nazmul Islam Nahid

Posted on • Updated on

#2.React Virtual DOM

What is the DOM?

The Document Object Model (DOM) is a programming interface for web documents. It represents the page so that programs can change the document structure, style, and content. The DOM represents the document as nodes and objects;
DOM specifies that querySelector() and it's return the element in the document.

const div = document.querySelector("#div");
Enter fullscreen mode Exit fullscreen mode

The Virtual DOM was not invented by React, but React uses it. It's a lightweight copy of actual DOM. Imagine a virtual DOM as a tree where each node represents a component. When we modify any component's state or data, a duplicate tree of that component and its children is regenerated, but other parent components are unchanged. React has two representations of virtual DOMs, which are the previous and new virtual DOMs. React simply compares these two and uses a diffing or reconciliation algorithm to determine their differences. After finding the change, React updates the specific DOM.
React has two representations of virtual DOMs, which are the previous and new virtual DOMs. React simply compares these two and uses a diffing or reconciliation algorithm to determine their differences.

Top comments (0)