Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/content/learn/updating-arrays-in-state.md
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,8 @@ ul, li { margin: 0; padding: 0; }

In `handleAddTodo`, you can use the array spread syntax. In `handleChangeTodo`, you can create a new array with `map`. In `handleDeleteTodo`, you can create a new array with `filter`. Now the list works correctly:

Here, `nextId++` mutates a module-level variable, but that's okay because `handleAddTodo` runs in response to a user event, not during rendering. The `todos` state itself is still updated immutably by passing a new array to `setTodos`.

<Sandpack>

```js src/App.js
Expand Down
Loading