const initialState = {
};
const reducer = produce((draft, action) => {
switch (action.type) {
case 'reset': {
draft = initialState;
break;
}
}, initialState);
draft = initialState not work, how can we reset draft to initial state in convenient?
Thank you
return initialState
Op zo 20 jan. 2019 04:47 schreef CodingPuppy notifications@github.com:
const initialState = {
};
const reducer = produce((draft, action) => {
switch (action.type) {
case 'reset': {
draft = initialState;
break;
}
}, initialState);draft = initialState not work, how can we reset draft to initial state in
convenient?Thank you
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/mweststrate/immer/issues/296, or mute the thread
https://github.com/notifications/unsubscribe-auth/ABvGhOMJx2gVTDeS98H7IaJ6_CS8ffO_ks5vE-bWgaJpZM4aJdDx
.
Thank you!
How is it possible to reset to initial state and then change a property of the draft?
To be equivalent to -
draft = { ...initialState, someProp: 'newVal' }
Thanks!
/cc @mweststrate
Use: return { stuff }
Op wo 8 jan. 2020 07:42 schreef lizagilman notifications@github.com:
How is it possible to reset to initial state and then change a property of
the draft?
To be equivalent to -
draft = { ...initialState, someProp: 'newVal' }Thanks!
/cc @mweststrate https://github.com/mweststrate
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/immerjs/immer/issues/296?email_source=notifications&email_token=AAN4NBAX72ZQPTGGE5EFRFLQ4V7XBA5CNFSM4GRF2DY2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEILPEPA#issuecomment-571929148,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAN4NBBZHWRZUFZX2ZX544LQ4V7XBANCNFSM4GRF2DYQ
.
Thanks for the quick reply @mweststrate .
I can return { ...initialState, someProp: 'newVal' }, but I would like to get rid of the spread syntax.
Here is my initial state:
const initialState = {
logs: {
error: false,
errorMessage: '',
pending: false,
fulfilled: false,
lines: '',
},
};
and I would like to first reset to this state and then update lines.
One way I can do that -
return { logs: { ...initialState.logs, lines: action.payload.data } }
Another way (which I'm not 100% sure is right) -
draft.logs = { ...initialState.logs };
draft.logs.lines = action.payload.data;
What would be the best way to do that? Can it be done without using spread?
Thanks.
@lizagilman please open new issues for new questions, as this one is closed already
(didn't notice that before as I was replying from mail, but replying to closed issues makes your problem invisible for everybody except those that are already in the convo, which is an completely unnecessary burden to the people already in this issue)
Most helpful comment
return initialState
Op zo 20 jan. 2019 04:47 schreef CodingPuppy notifications@github.com: