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");
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.
Top comments (0)