Why should you not change state directly?
Model answer
React decides to re-render only when you call the setter with a new value. Changing an object or array in place (items.push(x)) does not tell React anything changed, and the UI may not update. It also breaks features that compare old and new values.
Create a new copy: setItems([...items, x]) for arrays, setUser({ ...user, name }) for objects.
Learn this topic
React useState Explained: Make Your Page React to Change in the course React.js Full Course: Beginner to Advanced.
Sign in to add your own answer.