Complete State Update with Spread
Fill in the Blank Medium
Question
Fill in the blank to update the name property while keeping age.
Code
const [user, setUser] = useState({ name: "Alice", age: 30 });
setUser({ _____, name: "Bob" });
Hint
Use the spread operator to copy existing properties.
Explanation
The spread operator ...user copies all existing properties (name, age), then name: "Bob" overrides just the name. This creates a new object without mutating the original, which React requires to detect the change.
Related Resources
Related Lessons
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.