Reputation: 77
I have initialized a dynamic object array like 'flag: {833: true, 834: false, 835: false, 836: false}' and want update the value based on 'index' (e.g. flag[834] = true) & setState with the updated value (e.g. this.setState({ watchTopicFlag[index] : true }); ) at run time. How can we get this?
Upvotes: 0
Views: 402
Reputation: 30985
If your state is
this.state = {
watchTopicFlag: {
883: false,
774: false,
552: false
}
}
You can do
this.setState({ watchTopicFlag: {...this.state.watchTopicFlag, 883: true}})
Upvotes: 1