State changes when no reducer perform changes #2933
-
Hi all. Not sure if the title conveys its intended meaning, please bear with us. In a plain redux app (without redux-toolkit), when you dispatch an action and no reducer acts on that, then no change of state is notified. See console logs in this stackblitz. (Dependencies: redux 4.2.0) In a redux-toolkit app, in the same scenario, state changes are notified upon any dispatch, even if the state is not really changed. See console logs in this stackblitz. (Dependencies: @reduxjs/toolkit 1.9.0) Of course, it does not make sense to dispatch an action not mapped in any reducer. But this could simulate the case where a reducer maps on an action, but then no real state change is made. Is this behaviour intended? Does it cause any harm, e.g. to performance? Just to give some context: we are working on a custom store enhancer, which adds some info to the store, and at some point we were noticing state change notification even when nothing was really changing. So we started wondering whether it was our enhancer or what. Also, please point us in the right direction if this is not the right place for this topic. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
Can you clarify what those two examples are trying to show? They appear to be very different setups. For the record, the core Redux store always runs all subscriber callbacks (ie calls to |
Beta Was this translation helpful? Give feedback.
Can you clarify what those two examples are trying to show? They appear to be very different setups.
For the record, the core Redux store always runs all subscriber callbacks (ie calls to
store.subscribe(callback)
) after every action, regardless of whether the state was updated or not. RTK just ends up usingcreateStore
internally, so there is no difference in behavior between "vanilla Redux" and "RTK" here.