-
-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Unnecessary "Unexpected key ..." warning when merging combined reducers #2427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The point of using I'm going to say this is working as intended. Dynamic use of It's also easy enough to create a copy-paste version of |
I agree that it should be opinionated about what it does, but I guess I don't agree that it should so opinionated about what people do with it. After all, one of the huge advantages of Redux is that you can use function composition in all kinds of ways to create a reducer that produces the perfect state for your app.
The problem with this statement is that there is only a small number of cases where it is true (and you've just said that it's not worth catering for a small number of cases), assuming all the keys for the
(If there are more scenarios you can identify where having an additional key is more likely to be a mistake then not, then please reply and let me know). As I previously mentioned, the Redux docs even have a whole page dedicated to moving beyond
I understand this but I'd rather not have a unnecessary warning produced at all (how many times have you spent tracking down an issue that isn't really an issue?).
Unfortunately for me, I'm writing a library that must accept any reducer passed to it and they will often be created using I also imagine that many of the utilities in that list are using the built-in Given how definite your answer was (closed within 2 hours of opening without any other discussion or input), I'm not actually expecting you to reconsider now, I just hope that some of my points are taken into account when looking at a solution for #1636. |
I've found the behaviour of combineReducers oddly opinionated too since Redux itself is not very opionated but this is. I've often use a helper like this function composeReducers(...reducers) {
return (state = null, action) => {
return reducers
.filter(r => typeof r === "function")
.reduce((state, subReducer) => subReducer(state, action), state);
};
} which can used to put multiple reducers to same part of the state. const store = createStore(composeReducers(
myReducer,
myAnotherReducer,
combineReducers(...) // does not work
)); Unfortunately this does not work with combineReducers if one of my* reducers creates a new top level new key. :/ |
I am new to Redux, just followed the official document http://redux.js.org/docs/recipes/reducers/BeyondCombineReducers.html and ran into the same issue. |
Do you want to request a feature or report a bug?
A bug... maybe. It seems like it's intended behaviour but I don't know who benefits from the warning.
It is similar to #1636, but not caused by
replaceReducers
, but by wanting to merge the state from seperate reducers, which have been combined withcombineReducers
.What is the current behavior?
When
combineReducers
receives keys it doesn't know about it produces a warning statingIf the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://jsfiddle.net or similar.
Here is a codepen with a simplified example of what I'm doing.
What is the expected behavior?
I would not expect to see this warning, as I believe that merging state from multiple reducers is a valid use case for Redux. Even one of the examples in the Redux docs would have the same issue if the
crossSliceReducer
added a new key rather than overriding an existing one.I don't really understand who is benefitting from this warning. If it was warning about a missing key (after it has previously been there and there was a slice reducer expecting it) I would understand that that is something that is unusual and probably a bug, but I don't see much harm in having additional nodes that the reducer is just going to ignore anyway.
Which versions of Redux, and which browser and OS are affected by this issue? Did this work in previous versions of Redux?
I am unsure which version of Redux introduced the warning and why, but it is still present in 3.6.0
The text was updated successfully, but these errors were encountered: