Closed alexluong closed 4 years ago
Huh, I've never seen return void draft.count++
before :D Surprisingly enough, it's syntactically correct.
Ah, it's actually in README. Looks like a typo to me, should be without that void
if anything.
Either way, with Immer you don't need to be returning anything, just mutate values and done.
The return
in reducer is just for convenience because of the switch
so you can exit that specific case. Without return
or break
it would fall-through to the next case.
"Doesn't seem to work" is unactionable. Please include actual relevant information/ reproduction / example rather than making us guess what might be wrong.
There is no code / error shared at all. Filing issues this way is typically will get them closed without resolution.
Op do 31 okt. 2019 06:34 schreef Daniel K. notifications@github.com:
Huh, I've never seen return void draft.count++ before :D Surprisingly enough, it's syntactically correct.
Either way, with Immer you don't need to be returning anything, just mutate values and done.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/immerjs/use-immer/issues/37?email_source=notifications&email_token=AAN4NBDSC34JRRD5INRXSADQRJ37BA5CNFSM4JHBPX7KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECWWOVI#issuecomment-548235093, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAN4NBAJPKR5PLRTWH3NKXLQRJ37BANCNFSM4JHBPX7A .
@mweststrate you're right, my bad.
Like @FredyC suggested, not returning anything in the reducer function is fine. I didn't know that.
FWIW:
return void state.isOpen = true;
TS will underline =
and says ';' expected.
If anyone wants to still use void, you can do:
return void (state.isOpen = true);
But again, this works perfectly fine too:
state.isOpen = true;
return;
It would be good to update the readme to explain this.
When using
useImmerReducer
, I havereturn void draft.count++
but it doesn't seem to work. I'm quite new to bothimmer
and TypeScript. If anyone knows what's going on, I'd really appreciate your help.Thank you.