This content originally appeared on DEV Community and was authored by Siddharth Singh Bhadoriya
Lets start with a crisp-not-so-clear definition
Batching
Batching is when React groups multiple state updates into a single re-render for better performance.
Umm Question..Why Such a thing ?? Elaborating a bit..
In React, we can update the states of class components via setState() and update states of function components via hooks (i.e., useState()). These changes cause parts of the component tree to re-render. A naïve mechanism would be to re-render the component on every call of setState(), which would be inefficient when there are multiple calls of setState() inside a React event handler or synchronous lifecycle method.
React implements a batched updating mechanism to reduce the number of component renders. Consequently, multiple state changes will be batched into a single update, which will eventually trigger one re-render of a component.
For better understanding and clarity, go through this basic live example on my Stackblitz account.
This content originally appeared on DEV Community and was authored by Siddharth Singh Bhadoriya
Siddharth Singh Bhadoriya | Sciencx (2022-02-12T18:04:13+00:00) Beginners guide to React.js Batched Updates. Retrieved from https://www.scien.cx/2022/02/12/beginners-guide-to-react-js-batched-updates/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.