REACT RECONCILIATION ALGORITHM

Ravi Chandola
Javarevisited
Published in
2 min readFeb 3, 2023

Reconciliation is the process by which React updates the UI to reflect changes in the component state. The reconciliation algorithm is the set of rules that React uses to determine how to update the UI in the most efficient way possible.

React uses a virtual DOM (Document Object Model) to update the UI. The virtual DOM is a lightweight in-memory representation of the real DOM, which allows React to make changes to the UI without manipulating the actual DOM. This makes updates faster, as changing the virtual DOM is less expensive than changing the real DOM.

The reconciliation algorithm works by comparing the current virtual DOM tree to the updated virtual DOM tree, and making the minimum number of changes necessary to bring the virtual DOM in line with the updated state.

The algorithm uses two main techniques to optimize updates:

🚀 Tree diffing: React compares the current virtual DOM tree with the updated virtual DOM tree, and identifies the minimum number of changes necessary to bring the virtual DOM in line with the updated state.

🚀 Batching: React batches multiple changes into a single update, reducing the number of updates to the virtual DOM and, in turn, the real DOM.

The reconciliation algorithm is a critical part of React’s performance and helps make React one of the fastest and most efficient JavaScript libraries for building user interfaces.

After the reconciler compares the current and updated virtual DOM, it identifies the differences and makes the necessary changes to the virtual DOM to bring it in line with the updated state.

This updating of the virtual DOM is done for several reasons:

1. To keep the virtual DOM as an accurate representation of the current state of the components, so that it can be used in future updates.

2. To optimize updates to the real DOM. The virtual DOM provides a way for React to make changes to the UI without manipulating the real DOM directly. By making changes to the virtual DOM, React can determine the most efficient way to update the real DOM and make only the minimum number of changes necessary.

3. To ensure that the UI remains in sync with the state of the components. The reconciliation process ensures that the virtual DOM accurately reflects the current state of the components so that the UI remains up-to-date and in line with the state of the application.

In summary, the reconciler updates the virtual DOM after the reconciliation process to keep it accurate, optimize updates to the real DOM, and ensure that the UI remains in sync with the state of the components.

Please let me know your views too.

===================================================
SPECIAL THANKS TO Akshay Saini
===================================================

video credit — vattsal Bhatt

--

--

Ravi Chandola
Javarevisited

As a technology enthusiast, I have a passion for learning and sharing my knowledge with others. https://www.linkedin.com/in/ravi-chandola-304522133