What does the immutability check middleware do in Redux Toolkit? #6670
-
I am trying to learn Redux Toolkit and came across the default middleware for configureStore(): According to this page: Immutability check middleware: deeply compares state values for mutations. It can detect mutations in reducers during a dispatch, and also mutations that occur between dispatches (such as in a component or a selector). When a mutation is detected, it will throw an error and indicate the key path for where the mutated value was detected in the state tree. (Forked from redux-immutable-state-invariant.) I am confused. Aren't the reducers and dispatch function supposed to mutate state values? Why should errors ever be thrown? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Never mind. I got it. So we are supposed to return a new instance of our state in our reducers...ok! |
Beta Was this translation helpful? Give feedback.
Never mind. I got it. So we are supposed to return a new instance of our state in our reducers...ok!