https://codesandbox.io/s/92mk9n6vww
The remove reducer function violates purity.
remove(state, id) {
delete state[id] // <<< mutates state
return {
...state
}
}
Should be written in another way, e.g.
remove(state, id) {
return Object.keys(state).reduce(
(acc, cur) => {
if (cur === id) return acc
acc[cur] = state[cur]
return acc
},
{}
)
}
But that state is immediately replaced with a copy (and a new ref) of that state before anything else could read it...
If a tree falls in the woods and no one is there to hear it, does it make a sound?
In the current example it may be okay, but overall it is a bad practice, usually leading to bugs.
Feel free to close this issue if you think that it is not important for this case.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Closing as already fixed. Thanks!
Most helpful comment
In the current example it may be okay, but overall it is a bad practice, usually leading to bugs.
Feel free to close this issue if you think that it is not important for this case.