Answers for "how to add to and array in an object in react state"

4

add array of object to state react

setTheArray(currentArray => [...currentArray, newElement])
Posted by: Guest on November-07-2020
-1

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 "how to add to and array in an object in react state"

Browse Popular Code Answers by Language