add new array at the back of react state
this.setState(prevState => ({
myArray: [...prevState.myArray, "new value"]
}))
add new array at the back of react state
this.setState(prevState => ({
myArray: [...prevState.myArray, "new value"]
}))
how to add array data on state react
this.setState({ myArray: [...this.state.myArray, 'new value'] }) //simple value
this.setState({ myArray: [...this.state.myArray, ...[1,2,3] ] }) //another array
add new array at the back of react state
this.setState(prevState => ({
myArray: ["new value", ...prevState.myArray]
}))
add new array at the back of react state
this.setState(prevState => ({
myArray: [ {"name": "object"}, ...prevState.myArray]
}))
how to add array data on state react
// Using hooks
const [array, setArray] = useState([1, 2, 3])
setArray(prevArray => [...prevArray, 4]); // -> [1, 2, 3, 4]
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us