Thanks for this, i'm managed to rewrite a slightly ratty 388 line state controller for a complex 3 page form into 160 lines that are far easier to read. I see this as an absolute win.
@@hswolff thanks for the reply! Maybe something like after logging in, you hit this api: randomuser.me/ along with maybe some generic user info, along with a little CRUD? I guess I just wanted to see if immer/useReducer combo would be helpful when dealing with larger data sets.
@@benwozak5296 Yeah it'll definitely scale to a large app. The pitfalls section on immer has a good note too, item #3 immerjs.github.io/immer/docs/pitfalls Also I'd try it out and it's always easy to remove immer if you find you need to do your own hand rolled optimized update.
Don't really see the advantage of using immer with useReducer, maybe memory consumption and performance comparison can convince me it is worth the effort and fuss, besides, there is a better solution which is mobx and mobx-react-lite, and honestly, useContext and useReducer is powerfull enough for most scenarios.
Immer lets you use the same API as you do with MobX, i.e. directly mutating objects and arrays and not worrying about creating a new instance. Such that if you do use useReducer you can have that flexible API. If you go to my blog post hswolff.com/blog/level-up-usereducer-with-immer/#use-immer-with-usereducer you can see an example where Immer makes it much easier to update your state.
yeah i think immer's functionality/purpose is mainly to make state mutation easier. deep level objects can be tricky to not mutate when working with redux or useReducer hooks.... :)
Thanks for this, i'm managed to rewrite a slightly ratty 388 line state controller for a complex 3 page form into 160 lines that are far easier to read. I see this as an absolute win.
Yes! That's so great! I agree so much! So glad the video helped.
Hey Harry, hook man! 😀😀 Ever since I started following your channel, I've been having fun with React hooks, you had me hooked 😀😀😀
I hav been watching your videos nowadays ... You taught topics with the daily day usecases .thats why You are so specific than others.
Thank you! Nice tutorial, very informative 👏👏👏
Your video always productive, straight ahead and efficient, I'm your fans right now after finishing a few of your React related videos :)
So glad to hear! Happy to have you around!
Another great video, Harry. Makes you realize reducers aren't magic--that how to write the reducer depends on (lower case) context. Excellent work.
A great video on how to use immer with useReducer. Thanks, Harry
{2021-10-29}
I like the way you explain things. :)
Thank you!
This was really good explained! Thank you very much!
Thanks a lot. I refactored my code and it looks way more readable
Wow! Makes my life so much easier and cleaner with managing my state. This is what I've needed!! Can't wait to check out the next video in the series!
Thank for this awesome video
Thank you for watching!
This is AWESOME
Your channel is GOLDEN
Hahaha thank you!!
I can see this being very useful with a state with nested objects.
Wow-what an explanation!
thanks from Brazil.
Your videos are really appreciated, thanks! keep it up
Love it! Thank you!
thanks bro. I really love this tutorial
Thank you very much - it was great 😍✔😘
Awesome!!! Thanks man :)
You're welcome!
great video
Does having such mutable state manipulation affect performance? (Increase or Decrease)
Cool, man!
just subscribed
welcome!
Can you do this same example with something a little more complex like with axios and an external api or something like that?
What specifically are you curious about?
@@hswolff thanks for the reply!
Maybe something like after logging in, you hit this api:
randomuser.me/ along with maybe some generic user info, along with a little CRUD?
I guess I just wanted to see if immer/useReducer combo would be helpful when dealing with larger data sets.
@@benwozak5296 Yeah it'll definitely scale to a large app. The pitfalls section on immer has a good note too, item #3 immerjs.github.io/immer/docs/pitfalls
Also I'd try it out and it's always easy to remove immer if you find you need to do your own hand rolled optimized update.
please make a video how you organize your folder with reducer and context.
please please please
What if its an array how to mutate it and using the curriedImmer
Don't really see the advantage of using immer with useReducer, maybe memory consumption and performance comparison can convince me it is worth the effort and fuss, besides, there is a better solution which is mobx and mobx-react-lite, and honestly, useContext and useReducer is powerfull enough for most scenarios.
Immer lets you use the same API as you do with MobX, i.e. directly mutating objects and arrays and not worrying about creating a new instance. Such that if you do use useReducer you can have that flexible API.
If you go to my blog post hswolff.com/blog/level-up-usereducer-with-immer/#use-immer-with-usereducer you can see an example where Immer makes it much easier to update your state.
yeah i think immer's functionality/purpose is mainly to make state mutation easier. deep level objects can be tricky to not mutate when working with redux or useReducer hooks.... :)
not a single dislike :)
Hahaha! Hopefully that doesn't change!
@@hswolff really you can't dislike masterpiece like this one unless you are a complete sycophantic
IMO it would be fine to use break instead return in loginReducer . isnt?