Reputation: 125
I want to toggle this one boolean value in the state of one of my components. This is how I'm doing it rn :
updateProduct(productID) {
this.setState((prevState) => ({
content:{
...prevState.content
},
products:{
...prevState.products,
[productID] : {
...prevState.products[productID],
editable : !prevState.editable
}
}
}))
}
The problem is: This works, but only once i.e. It toggles the boolean from false to true, but then it gets stuck on being true.
Upvotes: 0
Views: 118
Reputation: 119
Shouldn't it be:
editable: !prevState.products[productID].editable
Upvotes: 2