Answers for "push objects into array react state"

4

add array of object to state react

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

add object to array setstate

To push to the beginning of the array do it this way

   this.setState( prevState => ({
     userFavorites: [{id: 3, title: 'C'}, ...prevState.userFavourites]
  }));
Posted by: Guest on October-06-2020

Code answers related to "push objects into array react state"

Browse Popular Code Answers by Language