0
Q:

how to update array in react state

this.setState({ myArray: [...this.state.myArray, 'new value'] }) //simple value
this.setState({ myArray: [...this.state.myArray, ...[1,2,3] ] }) //another array
3
this.setState(prevState => ({
  arrayvar: [...prevState.arrayvar, newelement]
}))
4
const [myArray, setMyArray] = useState([1,2,3])

// to update
setMyArray([...myArray, 4]); // --> myArray = [1,2,3,4]
0
{
  hasBeenClicked: false,
  currentTheme: 'bluesss',
}s
0
{
  hasBeenClicked: false,
  currentTheme: 'blue',
}
-1

New to Communities?

Join the community