From 0d15c0f1ee2bcb7ef4a974087f230e93436881fd Mon Sep 17 00:00:00 2001 From: rickvian aldi Date: Tue, 10 Nov 2026 02:08:41 +0000 Subject: [PATCH] docs: explain nextId mutation in array challenge --- src/content/learn/updating-arrays-in-state.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/content/learn/updating-arrays-in-state.md b/src/content/learn/updating-arrays-in-state.md index 61e4f4e2d98..48e42a6eb35 100644 --- a/src/content/learn/updating-arrays-in-state.md +++ b/src/content/learn/updating-arrays-in-state.md @@ -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`. + ```js src/App.js