Open In App

Explain dirty checks in React.js

Dirty Checks in React generally refer to the changes and modifications in the DOM if a component state is modified or dirtied and needs re-rendering making the React DOM updates efficient.

Prerequisites:

React uses virtual DOM to render the content. The DOM is an abstraction of a page’s HTML structure. It takes the elements and wraps them in an object with a tree structure. This provides an API that allows us to traverse the tree nodes and manipulate them such as adding nodes, removing nodes, or editing the contents of a node. DOM was intended for static UIs hence when the DOM updates, it has to update the node as well as the complete pages with their corresponding CSS and layout.



Dirty checks in React JS

DOM re-renders whenever there is a change in the data and it checks for data in two ways: 



React uses an observable technique whereas dirty checking is used in Angular.js.

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.

DOM updates in React:

Article Tags :