Answer the question
In order to leave comments, you need to log in
How to update a 2D array in state?
Array like:
Trying to update:
this.setState(prevState => {
return {
arr: {
...prevState.arr,
[posX]: [
...prevState.arr[posX],
[posY] = 1
]
}
}
})
const arr = [...this.state.arr];
arr[posX][posY] = 1;
this.setState({
arr: arr
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question