Govur University Logo
--> --> --> -->
...

In React, what is the primary difference in how `useState` handles updates compared to directly modifying a class component's `this.state`?



The primary difference lies in how React tracks and applies state updates, leading to different behaviors in re-rendering. When using `useState`, the update function returned by the hook (e.g., `setState`) enqueues a re-render of the component and performs a *shallow mergeof the new state with the previous state. A shallow merge means that the new state object's properties overwrite only the changed properties in the previous state, while the other properties remain untouched. This ensures that React knows the state has changed and can effici....

Log in to view the answer



Redundant Elements