react how to push to array in state code example
Example 1: add new array at the back of react state
this.setState(prevState => ({
myArray: [...prevState.myArray, "new value"]
}))
Example 2: how to update array in react state
this.setState(prevState => ({
arrayvar: [...prevState.arrayvar, newelement]
}))
Example 3: add new array at the back of react state
this.setState(prevState => ({
myArray: [...prevState.myArray, {"name": "object"}]
}))