Answers for "how to add javascript array to react state"

4

add array of object to state react

setTheArray(currentArray => [...currentArray, newElement])
Posted by: Guest on November-07-2020
6

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
Posted by: Guest on November-11-2020

Code answers related to "how to add javascript array to react state"

Browse Popular Code Answers by Language