Skip to content

Commit 0d15c0f

Browse files
committed
docs: explain nextId mutation in array challenge
1 parent 7594a2b commit 0d15c0f

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

‎src/content/learn/updating-arrays-in-state.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,8 @@ ul, li { margin: 0; padding: 0; }
12441244

12451245
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:
12461246

1247+
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`.
1248+
12471249
<Sandpack>
12481250

12491251
```js src/App.js

0 commit comments

Comments
 (0)