I am trying to update my state so that a nested array gets emptied but the rest of the state stays the same.
My state object looks like:
this.state = {
data: {
type: "FeatureCollection",
features: [1,2,3,4]
}
}
And I the closest I get to working is:
this.setState(prevState => ({
data: [...prevState.data, (this.state.data.features.length = 0)]
}));
The console warning I get with this approach is:
Do not mutate state directly. Use setState() react/no-direct-mutation-state
But how else is this possible?
Many thanks :)
setState.this.state.xxwhich seems more likely to be the problem.