-
Notifications
You must be signed in to change notification settings - Fork 298
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
Wrapping reducer in handleAction throws undefined state #23
Comments
Got this error too. Using |
yup, running into this as well. Seems like handleAction is broken with initial state being undefined... |
Happening for me too. Same workaround. I'm getting it because I'm passing the resultant reducer to |
i get this:
from this:
this is with redux-actions i'm assuming this is the same issue... |
Getting the same error , should be possible to do this: |
Same problem here when I define reducers with |
Same |
+1, this function is unhelpful as it stands. |
For others finding their way in here: Note that
|
Same problem. So handleAction is practically unusable, right? |
I don't know since when Redux is doing this sanity check, but without an initial state, Nevertheless, #55 adds support for that. |
Looking forward to this as well, going through the Redux tutorial and |
@timche isn't this closed with 0.10.0? |
Thanks for the reminder @yangmillstheory 👍 |
Solution: const someReducer = handleAction(someAction, (state, {payload}) => {
return {
...state,
...payload,
};
}, {}); // <-- default state The reason why this should be like this. Third param in |
You have to add default: return state; at the bottom of all cases of your switch function. Hope this work. Good luck |
If I wrap a reducer in
handleAction
I get this error:If I debug I see redux tries to get a initial state by calling the wrapped reducer with undefined state and a specific system action type. Because the type does not match the wrapped one the inner reducer never runs and no state default is created.
If I use
handleActions
(m) with default state it works fine. Same function with default state in arguments and classic action-type check is also fine.Anyway,is
handleAction
usable like this? Readme doesn't really specifiy use case.The text was updated successfully, but these errors were encountered: