Skip to content

Challenge Solution in "Updating Arrays in State" Page Uses Mutation #5672

Open
@edzhuang

Description

@edzhuang

For the solution to the third challenge in the Updating Arrays in State page, it uses the following function:

function handleAddTodo(title) {
  setTodos([
    ...todos,
    {
      id: nextId++,
      title: title,
      done: false
    }
  ]);
}

This changes nextId, a variable outside the component's scope, which I believe is a mutation. It should instead use the length of todos to set the next id.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions