immerjs / use-immer

Use immer to drive state with a React hooks
MIT License
4.04k stars 92 forks source link

When using a class with constructor, immer does not detect changes #31

Closed lucax88x closed 5 years ago

lucax88x commented 5 years ago

Hi guys, I don't know if this is a bug, but if it isn't, should be documented somewhere.

repro case:

https://stackblitz.com/edit/react-ts-qigunm

TLDR:

if you have class in the state, if this class has a constructor, and you pass values to it, when you try to modify a property of it on the reducer, immer does not detect that the property as changed, therefore does not trigger a rerender of the component and it stays the same value forever,

infos:

Help.

ps: let me know if I should address this one on the immer repository..

lucax88x commented 5 years ago

https://stackoverflow.com/questions/47672518/typescript-getownpropertynames-constructor-properties-vs-getter-setter

REALLY?

Could be the cause?

mweststrate commented 5 years ago

Please read the readme first on how to use immer with classes.

Op wo 14 aug. 2019 11:11 schreef Luca Trazzi notifications@github.com:

https://stackoverflow.com/questions/47672518/typescript-getownpropertynames-constructor-properties-vs-getter-setter

REALLY?

Could be the cause?

— 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/31?email_source=notifications&email_token=AAN4NBBU2CETIMFCV254NKTQEPK5LA5CNFSM4ILTDMO2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4IK4CY#issuecomment-521186827, or mute the thread https://github.com/notifications/unsubscribe-auth/AAN4NBG6QMQGYU6QJ4HSTKTQEPK5LANCNFSM4ILTDMOQ .

lucax88x commented 5 years ago

Ok, I can burn myself.

I'll close it, I hope at least it can help some poor guy like me in the web struggling with the same.

Thanks.