add new array at the back of react state code example

Example 1: add new array at the back of react state

this.setState(prevState => ({
  myArray: [...prevState.myArray, "new value"]
}))

Example 2: add new array at the back of react state

this.setState(prevState => ({
  myArray: ["new value", ...prevState.myArray]
}))

Example 3: add new array at the back of react state

this.setState(prevState => ({
  myArray: [...prevState.myArray, {"name": "object"}]
}))

Example 4: add new array at the back of react state

this.setState(prevState => ({
  myArray: [ {"name": "object"}, ...prevState.myArray]
}))

Tags:

Misc Example