-
-
Notifications
You must be signed in to change notification settings - Fork 848
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
Specify initial value of reducer #105
Comments
Hi Paul, could you set up a minimal reproduction in a codesandbox?
Op wo 21 feb. 2018 om 09:24 schreef Paul Klimashkin <
notifications@github.com>:
… Hello!
Sorry if it's been discussed or documented, but I could not find solution.
How to specify initial value of reducer in case of currying?
If on first @@redux/INIT run I don't do anything with draft, redux
complains about returned undefined during initialization. If the state
passed to the reducer is undefined, you must explicitly return the initial
state.. But if I do
some: produce((draft, action) => {
if (draft === undefined) {
return {};
}
}
redux throw the same error...
Using version 1.1.0, and I though that returning object from producers
should already work, strange.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#105>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABvGhA4PtdZ-y8N5KSdx9G3nKWh_Urcuks5tW9KlgaJpZM4SNO6w>
.
|
Created simple pen where returning from currying doesn't work: I found in the doc:
Seems like the only way is to pass initial value on store startup, but it's not convenient in redux world. const counter = produce((draft, action) => {
switch (action.type) {
case 'INCREMENT':
return draft.count += 1;
case 'DECREMENT':
return draft.count -= 1;
}
}, {count: 0}); |
@klimashkin apologies, this was a bug in the currying! Should be fixed in 1.1.1 |
Thanks @mweststrate! What do you think about setting default value as a second parameter of curried |
@klimashkin could you open a separate issue for that? |
Hello!
Sorry if it's been discussed or documented, but I could not find solution.
How to specify initial value of reducer in case of currying?
If on first
@@redux/INIT
run I don't do anything with draft, redux complains aboutreturned undefined during initialization. If the state passed to the reducer is undefined, you must explicitly return the initial state..
But if I doredux throw the same error...
Using version
1.1.0
, and I though that returning object from producers should already work, strange.The text was updated successfully, but these errors were encountered: