This is an answer I found on Github and is much better than the selected answer. https://github.com/immerjs/immer/issues/619#issuecomment-644393613
cloneDeep will always fully clone your entire state. This causes two fundamental problems which makes it quite unusable to use with react for any slightly significant amount of data:
- deepClone is very expensive. You have a collection of 100 items? All those items will continuously be retreated on every update. Hitting both the performance and the garbage collector badly
- deepClone can't leverage memoization, because the "same" objects will not be refererrentially equal after every update. So it means that react will always need to rerender all your components. Which basically kills all benefits that immutability would offer you in the first place.
In other words, deepClone, unlike produce, doesn't offer structural sharing of all the unchanged parts of your state after an update