Open In App

What is Diffing Algorithm ?

Diffing Algorithm in React JS differentiates the updated and previous DOM of the application. DOM stores the components of a website in a tree structure. React uses virtual DOM which is a lightweight version of the DOM. The only difference is the ability to write the screen like the real DOM, in fact, a new virtual DOM is created after every re-render.



What is Diffing Algorithm in React ?

Diffing short for Differences Algorithm is used to differentiate the DOM Tree for efficient updates. React utilize diffing algorithm to identify the changes in the newly created virtual dom and previous version of dom after any changes are made.

How Diffing Algorithm Works?

Assumption for Diffing Algorithm

React uses a heuristic algorithm called the Diffing algorithm for reconciliation based on these assumptions:



React checks the root elements for changes and the updates depend on the types of the root elements,

Note: This is the reason why we should always use unique keys in the elements so that it will be easy for React to determine changes in the elements.

Advantages of Diffing Algorithm:

Article Tags :