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