Please give me answer. #86796
-
|
What happens in React from the moment setState is called until the UI updates? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
When setState is called, React creates an update object and places it in the component’s update queue. The scheduler assigns a priority to the update and marks the affected Fiber subtree as dirty. React then enters the render (reconciliation) phase, building a work-in-progress Fiber tree by running beginWork and completeWork on each Fiber. This phase is interruptible. React collects all necessary DOM changes in an effect list. When the render phase completes, React enters the synchronous commit phase, applies DOM mutations, runs layout effects, triggers the browser paint, and finally runs passive effects. At the end, React swaps the new Fiber tree into place, and the UI is updated. |
Beta Was this translation helpful? Give feedback.
When setState is called, React creates an update object and places it in the component’s update queue. The scheduler assigns a priority to the update and marks the affected Fiber subtree as dirty. React then enters the render (reconciliation) phase, building a work-in-progress Fiber tree by running beginWork and completeWork on each Fiber. This phase is interruptible. React collects all necessary DOM changes in an effect list. When the render phase completes, React enters the synchronous commit phase, applies DOM mutations, runs layout effects, triggers the browser paint, and finally runs passive effects. At the end, React swaps the new Fiber tree into place, and the UI is updated.