Earlier quoted context omitted.
FWIW, React has always been designed around some Functional Programming type principles, such as immutable updates. Immutable updates do in fact require that if you want to update `state.some.nested.field`, you have to make copies of _all_ objects in that path: `nested`, `some`, and `state`. This isn't unique to React. Yes, class component `this.setState()` lets you get away with mutations. That's not really a _good_…
When updating deeply-nested immutable objects, the Immer library is great. You call the `produce(immutableValue, draft => { ... })` function with some immutable value and a callback function that manipulates a mutable proxy object mimicking the immutable value, and then the function returns a new immutable value with the same changes made by the callback function. The mutable proxy object never escapes the callback,…
I had catalogued _dozens_ of immutable update libs between 2015-2018, and Immer is simply superior to all of them.
Which is why Immer is a non-negotiable part of RTK, and something we specifically tell everyone they should be using with Redux:
- https://redux.js.org/style-guide/#use-immer-for-writing-immu...
- https://redux-toolkit.js.org/usage/immer-reducers
(in fact, I recently got quoted on the top of the Immer docs with a tweet I wrote saying how awesome Immer is :) https://immerjs.github.io/immer/ )