Find: Direct State Mutation
Find the Mistake Medium
Question
What is wrong with this state update?
Code
const [items, setItems] = useState([1, 2, 3]);
items.push(4);
setItems(items);
Hint
State should never be mutated directly.
Explanation
The code mutates the state array directly with items.push(4), then passes the same reference to setItems. React compares references and sees no change, so it doesn't re-render. The fix is: setItems([...items, 4]); to create a new array.
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.