Answers for "update object in array state by index"

0

update object in array state react

const handleAdd = (todo) => {
  const newTodos = [...todos];
  newTodos.push(todo);
  setTodos(newTodos);
}
Posted by: Guest on July-23-2021
0

update object in array state by index

this.setState(({items}) => ({
    items: [
        ...items.slice(0,1),
        {
            ...items[1],
            name: 'newName',
        },
        ...items.slice(2)
    ]
}));
Posted by: Guest on January-09-2021

Code answers related to "update object in array state by index"

Code answers related to "Javascript"

Browse Popular Code Answers by Language