Virtual DOM
-
This lesson explains the Virtual DOM in React and how it helps efficiently update the user interface by reducing direct DOM operations.
What is DOM?
DOM (Document Object Model) represents the structure of a web page.
Example:
HTML → DOM Tree
Problem with Real DOM:
Updating DOM is slow
Full re-render affects performance
What is Virtual DOM?
The Virtual DOM is a lightweight copy of the real DOM stored in memory.
React uses Virtual DOM to improve performance.
How React Updates the UI Efficiently
Steps:
UI change occurs
React updates Virtual DOM
React compares old and new Virtual DOM
Finds the difference (diffing)
Updates only the changed part in Real DOM
This process is called Reconciliation.