Answers for "add object in array state react"

5

how to add array data on state react

this.setState({ myArray: [...this.state.myArray, 'new value'] }) //simple value
this.setState({ myArray: [...this.state.myArray, ...[1,2,3] ] }) //another array
Posted by: Guest on November-11-2020
0

add object in array state react

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

Code answers related to "Javascript"

Browse Popular Code Answers by Language