H
H
Higrok2021-05-01 18:46:45
React
Higrok, 2021-05-01 18:46:45

How to change state without crutches?

There is a state :

state = {
    todos: [
      { id: 1, text: "Test", isSuccess: false },
      { id: 2, text: "Test 2", isSuccess: false }
    ],
    todosText: null
  };


How can I change the value of isSuccess of a certain object without crutches?

All code if needed: https://pastebin.com/b2a83gyU

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-05-01
@Higrok

this.setState(({ todos }) => ({
  todos: todos.map((n, i) => i === index
    ? { ...n, isSuccess: true }
    : n
  ),
}));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question