You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What is the new or updated feature that you are suggesting?
I would like to see state - the entire, full state, not just the slice - passed as the 3rd argument to a reducer used in combinedReducers.
Why should this feature be included?
combineReducers is wonderful for creating nicely separated, logically consistent reducers. However, there's occasionally edge cases where it is justifiable for one reducer to need data from another. Right now it requires some messy code, either special casing a middleware to attach additional data, arbitrarily getting the store, or awkwardly pulling in extra data to an action when it's created.
With state as a 3rd arg it would be possible to grab the required data easily and cleanly. I think this is actually the biggest downside of it as well, since it could encourage abusing this ability to write reducers that break outside their bounds more often than just edge cases.
It would be fully backwards compatible since no reducer expects a 3rd arg right now.
The core code change for this is just a few characters, I wrote this when I realized I'd have to also update the types & tests but could do a PR for this if it's something that would be considered.
The text was updated successfully, but these errors were encountered:
The problem is: which state are you expecting to be passed? The one from before the reducer ran, or passed from other reducers? In the latter case, how do you control ordering? What about circular dependencies?
It's not an easy problem to solve, because the answers to those questions mean different things to different people. We've discussed this quite a bit in #2795, #2750, #1904, #1768, and #1527. It's also related to #1518 and #1400.
The conclusion is there isn't a comprehensive answer that also keeps in line with the central tenants of Redux.
Do you want to request a feature or report a bug?
Feature
Prior Issues
None
New Features
What is the new or updated feature that you are suggesting?
I would like to see
state
- the entire, full state, not just the slice - passed as the 3rd argument to a reducer used incombinedReducers
.Why should this feature be included?
combineReducers
is wonderful for creating nicely separated, logically consistent reducers. However, there's occasionally edge cases where it is justifiable for one reducer to need data from another. Right now it requires some messy code, either special casing a middleware to attach additional data, arbitrarily getting the store, or awkwardly pulling in extra data to an action when it's created.With
state
as a 3rd arg it would be possible to grab the required data easily and cleanly. I think this is actually the biggest downside of it as well, since it could encourage abusing this ability to write reducers that break outside their bounds more often than just edge cases.It would be fully backwards compatible since no reducer expects a 3rd arg right now.
What docs changes are needed to explain this?
https://redux.js.org/api/combinereducers/ & maybe https://redux.js.org/basics/reducers/ 's section on
combineReducers
The core code change for this is just a few characters, I wrote this when I realized I'd have to also update the types & tests but could do a PR for this if it's something that would be considered.
The text was updated successfully, but these errors were encountered: