How does React renderer work exactly when we call setState ?
How does React renderer work exactly when we call setState ?
When setState is called in a React component, it triggers a process that leads to potential updates in the component's output in the Document Object Model (DOM). Here's a detailed breakdown of how this process works:
setState When setState is invoked, it schedules an update to a component's state object. This method does not immediately update the component but rather enqueues changes to the component's state.
setState is asynchronous, which means React may batch or defer the update until later. This batching optimizes performance by grouping multiple state updates into a single re-render for better performance.
Once state updates are processed, React enters the reconciliation phase. During this phase, React compares the new state and props of the component with the previous state and props to determine if the component needs to be re-rendered.
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.