Fügen Sie das Neue Array im hinteren Teil des React -Zustands hinzu
this.setState(prevState => ({
myArray: [...prevState.myArray, "new value"]
}))
Worrisome Weevil
this.setState(prevState => ({
myArray: [...prevState.myArray, "new value"]
}))
this.setState({ myArray: [...this.state.myArray, 'new value'] }) //simple value
this.setState({ myArray: [...this.state.myArray, ...[1,2,3] ] }) //another array
// Using hooks
const [array, setArray] = useState([1, 2, 3])
setArray(prevArray => [...prevArray, 4]); // -> [1, 2, 3, 4]