No. this.setState merges new fields into the existing state object. useState replaces the value entirely. So when storing an object in useState, you must spread the old fields manually to preserve them.
Does useState merge state like this.setState?
More FAQs in useState vs Class Component State: What's Different?
Class state lived in a single this.state object updated with this.setState, which merged new fields. useState gives separate variables and setters, and updating replaces the value rather than merging, so you spread objects manually.
It encourages small, focused state variables that are easier to reason about, removes the confusing this keyword and its binding issues, and lets you organize related logic in custom hooks instead of splitting it across lifecycle methods.
useEffect. Class components used separate lifecycle methods like componentDidMount and componentDidUpdate. Functional components use useEffect, which combines mounting, updating, and unmounting into a single API.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.