Good day! I have a nested state with array children, and I would like to know the correct and best way to setState.
Here's a sample state object.
EDITED, Forgot to mention that lists is an array of objects.
this.state = {
lists:
[{
name: 'sampleList',
id: 15,
permission: {
canRead: true,
canWrite: false
}
}]
}
}
I use this to setState of the permission's properties but the state is not updated.
this.setState({
...this.state, lists: {
...this.state.lists, key: [
...this.state.lists.key, permission : {
...this.state.lists.key.permission,
canRead: !this.state.lists.key.permission.canRead
}
]
}
});
I hope you can help me. Thanks!