Skip to content

Mutating state #32

Description

@pobch

I think you are mutating the state at the following lines:

const notes = [...state.notes]
notes[index].completed = !note.completed

Since each note is an object, setting notes[index].completed property is mutating the note object. Instead, we should create a new note object like this:

const notes = [...state.notes]
notes[index] = { ...state.notes[index], completed: !note.completed }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions