Stage 1 · Lesson 4 of 9
Immutable updates
React redraws a screen when state changes. It checks for a change by reference: is this the same object as before? If you push to an array or change an object's field in place, the reference stays the same, so the screen may not update.
That is why you always create new values instead, with the and array methods. To add, write [...todos, newTodo]. To remove, write todos.filter((t) => t.id !== id).
To change one item, write todos.map((t) => (t.id === id ? { ...t, done: true } : t)). Spread is shallow: it copies only the top level, so a nested object needs copying at each level you change. Learning this now, in plain , saves days of confused debugging once you add state to components.
A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- CoursePaidGrokking JavaScript Fundamentals
Design Gurus · Beginner · $50
Beginner JavaScript with an exercise after most lessons
- GuideFreeJavaScript.info
Ilya Kantor
Free and thorough: Part 1 is the language, skip the browser chapters in Part 2