Skip to content

Latest commit

 

History

History
15 lines (8 loc) · 1.23 KB

File metadata and controls

15 lines (8 loc) · 1.23 KB

Which is faster virtual DOM or Real DOM in React JS?

In React, the Virtual DOM is typically faster than the Real DOM, and this is one of the key reasons behind React's performance optimization.

Here's how it works:

  1. Virtual DOM: When you make changes to the state or props of a React component, React doesn't immediately update the Real DOM. Instead, it creates a virtual representation of the DOM, known as the Virtual DOM. This is a lightweight copy of the Real DOM.

  2. Reconciliation: React then compares the previous Virtual DOM with the new Virtual DOM to determine what has changed. This process is called "reconciliation."

  3. Minimal Updates: React calculates the minimum number of updates needed to bring the Virtual DOM in sync with the Real DOM.

  4. Real DOM Updates: Finally, React updates the Real DOM with the minimal set of changes needed to reflect the new state. These updates are typically much faster than if you were to manually manipulate the Real DOM directly.

  5. The Virtual DOM helps in reducing the number of updates to the Real DOM and avoids direct manipulation of the Real DOM, which can be slow and inefficient. It optimizes the rendering process, making React applications faster and more efficient.