React Rendering Explained: Rendering vs DOM Update

REACT INTERNALS - PART 1 What Does “Rendering” Actually Mean? In React, we often say: “This component re-rendered.” But rendering does NOT mean the browser immediately updated the screen. When you click a button that updates state, here’s what actually happens: 1. setState (or setCount) updates the state value 2. React schedules an update 3. The component function runs again 4. React calculates what the UI should look like now This calculation phase is called rendering. At this stage, React creates a new Virtual DOM - a lightweight JavaScript representation of the UI. The browser, however, works with the Actual DOM - the real structure displayed on the screen. Updating the Actual DOM is expensive because it can trigger layout recalculation, repaint, and reflow inside the browser. To avoid unnecessary work, React compares the new Virtual DOM with the previous one. Only after finding differences does it update the Actual DOM. So the key idea is: Rendering = recalculating the UI DOM update = applying real changes in the browser They are not the same thing. Understanding this separation is the first step toward understanding performance in React. To understand this better, refer to the example attached below. Next: How React compares the old and new Virtual DOM - reconciliation. #ReactJS #FrontendDevelopment #JavaScript #ReactInternals #SoftwareEngineering

  • graphical user interface, text

Greatly explained. Rendering(calculations) is done Off-screen.

Such good explanation of rendering , Will wait for reconciliation

See more comments

To view or add a comment, sign in

Explore content categories