Zustand - Complete Tutorial

Sdílet
Vložit
  • čas přidán 17. 12. 2023
  • Join The Discord! → discord.cosdensolutions.io
    Source Code → github.com/cosdensolutions/co...
    VSCode Theme | Font → Material Theme Darker | Menlo, Monaco "monospace"
    In this video we will learn about Zustand in React. Zustand is a popular state management library for React that makes it really easy to have global state in your React application. Similarly to Redux, Zustand works with the concept of stores, provides you custom hooks to use directly in React components, and also allows you to easily write global state and scale your React applications. This is the last Zustand tutorial you'll ever need to watch!

Komentáře • 198

  • @xanteI
    @xanteI Před 7 měsíci +57

    About the second best practice. Zustand documentation does not recommend creating multiple stores, they recommend creating slices grouped by functionality, and then spread the slices into the main store. I see this inaccuracy in almost all videos and articles on Zustand

    • @cosdensolutions
      @cosdensolutions  Před 7 měsíci +15

      Aha, you're correct. I had my terminology mixed up

    • @user-qq8ms6dp7e
      @user-qq8ms6dp7e Před 7 měsíci

      hey, could you link this?

    • @rodjenihm
      @rodjenihm Před 6 měsíci

      @@user-qq8ms6dp7e Google "Slices pattern Zustand"

    • @xanteI
      @xanteI Před 5 měsíci

      ​@@den9943, yea, it's flux inspired architecture

    • @venicebeachsurfer
      @venicebeachsurfer Před 4 měsíci

      This is not true. It is recommended because it is the most popular pattern, BUT there is no benefit to do this other than sticking the whole state under the devTools. Why would you want to include the whole state on a page that only cares about a small slice of it? Performance wise, you'd want seperate stores, I think.

  • @zebcode
    @zebcode Před 4 měsíci +11

    What i love the most about this video is that you do one thing at a time and explain it. So many people do 10 things at once leaving viewers confused and frustrated. Its slightly slower than I required but then you maintain a good cadance. You don't spend time over explaining things.

  • @vladislaviy
    @vladislaviy Před 7 měsíci +8

    Man you explanaitions of Redux and Zustand are the Top on youtube in terms of how fast and clear you provide it.. thank you!!!

  • @yashpatidar.8506
    @yashpatidar.8506 Před 7 měsíci +11

    I've watched many videos about Zustand, but only this one has clarified all my doubts. It's the best resource on the topic. Thank you for creating such an awesome and enlightening video! 👏🎉

  • @julienheng3880
    @julienheng3880 Před 7 měsíci +7

    This is what I had anticipated for. Great tutorial as always. Thank you very much!

  • @aryansuvarna4923
    @aryansuvarna4923 Před 7 měsíci +4

    literally started learning Zustandd yesterday. THIS VIDEO IS A GOD SEND!

  • @alkadoHs
    @alkadoHs Před 7 měsíci +9

    Sir, now i should register you to my book as my favorite react teacher. You explain things very clear while keeping the best practices, awesome 😎

  • @rameezh88
    @rameezh88 Před 7 měsíci

    Great tutorial. Concise, clear, and quick. Just stumbled upon your video when I was thinking about learning exactly this. Thank you!

  • @camilo5821
    @camilo5821 Před 7 měsíci +1

    thanks man!, i really enjoy your videos and shorts.

  • @VladyslavDihtiarenko
    @VladyslavDihtiarenko Před 5 měsíci +3

    19 minutes, and I can already use Zustand now. Thank you so much! Very straightforward explanation!

  • @cslearn3044
    @cslearn3044 Před 7 měsíci +2

    I legit starter learning zustand again yesterday lol, thank you!

  • @nickwithaz
    @nickwithaz Před 4 měsíci

    Great video - really clear explanation of the key concepts and how to apply them - thanks!

  • @ToumaRenshi
    @ToumaRenshi Před 4 měsíci

    great tutorial, i just started to learn about zustand from yesterday and today i am getting more to understand now. thank you! :)

  • @TannerBarcelos
    @TannerBarcelos Před 7 měsíci +1

    Zustand is amazing. So light, simple and powerful.

  • @letaciogalvao9908
    @letaciogalvao9908 Před 5 měsíci

    Completely awsome, just learned and already implemented in my job! Thanks a lot!

  • @tomasburian6550
    @tomasburian6550 Před 7 měsíci

    This vid made me sub to you. Lots of good info on this channel.
    Keep it up!

  • @Deepakkumar431
    @Deepakkumar431 Před 6 měsíci +1

    Accurate, to the point. Thanks a lot for sharing.

  • @freeshorts4423
    @freeshorts4423 Před 6 měsíci

    you are really amazing sir. best react tutorial ever. lots of love from NEPAL

  • @peterng.
    @peterng. Před 6 měsíci

    That's awesome!!
    Very concise, clear, and well-explained!
    Keep up the great work, man!

  • @r34ct4
    @r34ct4 Před 5 měsíci +1

    Absolutely brilliant tutorial, It's rare that I understand something so organically and easily, props to you brah

  • @YosephTeki
    @YosephTeki Před 25 dny

    thanks mate, simple and straightforward explanation

  • @OmarAmeen-sb8bt
    @OmarAmeen-sb8bt Před 5 měsíci

    you are awesome learned a lot from this session it is definitely a premium content

  • @gmjitendra
    @gmjitendra Před 7 měsíci

    One more excellent learning. Thank you so much.

  • @larrymcfarlane6202
    @larrymcfarlane6202 Před 5 měsíci

    Concise and to the point. Thanks!

  • @someone-on-earth
    @someone-on-earth Před 2 měsíci +1

    Very easy to understand Zustand from this video, I've watched like 3-4 tutorials and was still confused as to what is really happening

  • @giovanio.3581
    @giovanio.3581 Před 5 měsíci

    Thanks for the tutorial, It was very easy to understand

  • @uncore_
    @uncore_ Před 7 měsíci +1

    Great video.I just want to make something more clear tough, the first practice you mention in the video does also go for redux and the reason why this works is because (old) { } === (new) { } would evaluate as false thus will be treated as state update,but say count is 1 then (old) 1 === (new) 1 would evaluate as true so no updates required

  • @evanh.3744
    @evanh.3744 Před 5 měsíci

    clear and so helpful! it just what i need.thank you

  • @TheFatafillo
    @TheFatafillo Před 7 měsíci +5

    Great video, great explanation. Just a quick note: Would not be more nice to write handler functions and reference instead of arrow functions everywhere because in a real application there should be some testing for functionalities and named functions make this easier. Reading the code is more easier as well.

  • @_ayush_oswal
    @_ayush_oswal Před 4 měsíci

    Really concise and easy to follow!!

  • @zerdnelemo
    @zerdnelemo Před 4 měsíci

    Great video and great tool. I will give it a try.

  • @jeetdesaimusic
    @jeetdesaimusic Před měsícem

    Amazing Explanation sir!

  • @rohitghadage3220
    @rohitghadage3220 Před 7 měsíci

    You are one of the best CZcamsr✨

  • @arghyadas4138
    @arghyadas4138 Před 5 měsíci

    Great content
    Subscribed 🙌

  • @Ksahdia
    @Ksahdia Před 7 měsíci

    When I saw the video title, I thought we had to learn React in German now and wondered if that was the new trend or something. Never heard of Zustand before, thanks for the explanation!

  • @collinsk8754
    @collinsk8754 Před dnem

    Excellent tutorial!

  • @user-xu9tb7oe2z
    @user-xu9tb7oe2z Před 5 měsíci

    brilliant education work! thanks!

  • @nfaical3
    @nfaical3 Před 7 měsíci +1

    Thanks 👍, nice explanation

  • @dukeselwood
    @dukeselwood Před 3 měsíci

    Excellent tutorial, thanks

  • @rdx86
    @rdx86 Před 2 měsíci

    Fantastic video, very easy to follow and understand. I'd love to see a video on Jotai as well. We've been using it a lot at work and have loved it so far. Only problem is that we can't access the Atom states outside of React components, unlike Zustand.

  • @Jaracara11
    @Jaracara11 Před 5 měsíci

    Excellent video!

  • @0ninetyseven97
    @0ninetyseven97 Před 7 měsíci

    this gut deserves a million subs

  • @omaracelys3217
    @omaracelys3217 Před 7 měsíci

    Thank you for the video !
    One recommandation,
    go through the documentation while coding,
    it helps to understand how to get used to the doc,
    because that can more maintanable et useful in my exprience

  • @lutzruhmann7162
    @lutzruhmann7162 Před 6 měsíci

    This was very helpfull, Thanks!

  • @minusmarigold98
    @minusmarigold98 Před 5 měsíci

    man , you are really best!

  • @koleen3799
    @koleen3799 Před měsícem

    Thanks a lot, mate! 🎉

  • @hanspen5978
    @hanspen5978 Před 7 měsíci

    on point, I want to make a cart with it tomorrow

  • @llibanogs
    @llibanogs Před 16 dny

    great vid buddy

  • @chrishanthacosta4093
    @chrishanthacosta4093 Před 4 měsíci

    best zustand video..thanks

  • @lucasyang7726
    @lucasyang7726 Před 7 měsíci

    Great video🎉

  • @omarmoustafa2652
    @omarmoustafa2652 Před 26 dny

    This is really awesome

  • @felix_nope
    @felix_nope Před 4 měsíci

    Really nice video, but it made me flinch every time you said “Zustand.” :D

  • @Ameer_Ameen
    @Ameer_Ameen Před 2 měsíci

    oh man idk how to thank you, you just saved me from spending money just to learn zustand .

  • @gowthamsrinivasan9285
    @gowthamsrinivasan9285 Před 7 měsíci

    Great video

  • @flwi
    @flwi Před 3 měsíci

    This looks interesting. Thanks for showing what zustand can do! I'm not a big fan of accessing & manipulation the state from "everywhere" though, since it has spaghetti-code-potential imo.

  • @rogeert
    @rogeert Před 7 měsíci +4

    I love Zustand.
    Can you make a video about signals?

  • @user-vu6kk1rc6g
    @user-vu6kk1rc6g Před 15 hodinami

    thank you very berief and useful

  • @fabianopereira1011
    @fabianopereira1011 Před 5 měsíci

    Obrigado, me ajudou muito.

  • @thatsenoughdixit
    @thatsenoughdixit Před 4 měsíci

    Love thisss

  • @lekandar4889
    @lekandar4889 Před 7 měsíci

    Thanks man

  • @mrvfino
    @mrvfino Před 4 měsíci

    Thanks!

  • @harag9
    @harag9 Před 7 měsíci +3

    Great tutorial. I watched your Redux video a couple of weeks ago and now this... Since I'm still learning, which one would you recommend ? Would be nice to have a comparison video of pros & cons of them both.

    • @mleite1
      @mleite1 Před 7 měsíci

      Redux is like a dinosaur..

    • @cosdensolutions
      @cosdensolutions  Před 7 měsíci +2

      Zustand is simpler and less intimidating. There's less boilerplate code. Redux has been around for longer and is more stable. Both are great tbh and it really depends on more specific use cases in your project that put you towards one or the other!

  • @mjylove2
    @mjylove2 Před měsícem

    thank you so much

  • @reydantegarcia8776
    @reydantegarcia8776 Před měsícem

    Thank you, great tuts. By the way, what extension that provides a code suggestion?

  • @pixyoutube538
    @pixyoutube538 Před 7 měsíci

    Very helpful

  • @fluxsiarski
    @fluxsiarski Před 19 dny

    Good stuff

  • @emirkehribar5089
    @emirkehribar5089 Před 6 měsíci +2

    Hi, can you turn off copilot next time, please? It's very distracting.

  • @SKKhandokar
    @SKKhandokar Před 2 měsíci

    I want using react react-query data store in zustand. How can i do it?

  • @blankvoid4137
    @blankvoid4137 Před 2 měsíci

    I'm having trouble making zustand work together with zusty and persist. How to use multiple middlewares together? Like persit, immer together. Also add dev tools to it?

  • @Mrkostas7777ify
    @Mrkostas7777ify Před 7 měsíci +1

    Can you also prepare a video for Jotai? It would be very useful since it gains popularity

  • @joerodrigo9661
    @joerodrigo9661 Před 6 měsíci

    I have been using zustand for my react-native projects for a month now, its nice, but I have a question, how do we implement encryption in zustand when using persist?

  • @fernandosoaresdev
    @fernandosoaresdev Před 7 měsíci

    This is a great video, Derick! I have a doubt, if I may: StrictMode runs every hook twice, right? Why should we use StrictMode, and why/when no to use it? Thanks man, happy holidays!

    • @cosdensolutions
      @cosdensolutions  Před 7 měsíci

      Strict mode is there to prevent you from making mistakes in hooks and not cleaning up your dependencies. Ideally, it shouldn't affect you as you develop if you use it so I would keep it and see if anything breaks. If it does, then you might have a bug!

    • @chinmayghule8272
      @chinmayghule8272 Před 6 měsíci

      @@cosdensolutions Strict mode only re-renders in development (to catch bugs related to state or effects) and works normally in production where you use the build. The build runs normally.

  • @kousheralam8657
    @kousheralam8657 Před 5 měsíci

    Hi, Is there any best practice for store dependecy, example:- i have two store
    1. User store {username, userid}
    2. Invoice store {fetchInvoiceByUserId}
    to fetch the invoice by user id what i can do, i can take a parameter in fetchInvoiceByUserId function,
    Is it the only way, or is there any best practice around it ?

  • @Di-yes
    @Di-yes Před 7 měsíci +1

    Question. Heard that to avoid rerenders it's better to use reselect with Redux. Is it required here aswell?

    • @cosdensolutions
      @cosdensolutions  Před 7 měsíci +1

      In here, you just need to select the state you want and that will cover a lot of your re-rendering issues

  • @user-qq8ms6dp7e
    @user-qq8ms6dp7e Před 7 měsíci +1

    what about something like
    const { count, increment } = useStore();
    would that still be inefficient?

    • @sep1ol
      @sep1ol Před 6 měsíci

      i have the same question
      did you figure this out?

  • @battulabalakrishna8062
    @battulabalakrishna8062 Před 5 měsíci

    After refresh state is setting to default value!, for redux we have redux-persist do we have anything like that in zustand

  • @saurabhu6458
    @saurabhu6458 Před 7 měsíci +1

    Please make video on signals😊

  • @milanzmitrovic
    @milanzmitrovic Před 5 měsíci

    What tool do you use for autocomplete? Is it some kind of AI assistant?

  • @patrickmichael4113
    @patrickmichael4113 Před 7 měsíci

    Very insightful. now i got a hang of it. please sir how do you get those code suggestions in your ide?

  • @Lagtcham
    @Lagtcham Před 29 dny

    Is it possible to have several stores and view both in the devtools?

  • @KylanHurt
    @KylanHurt Před 5 měsíci

    Would be cool if you showed how to install the Zukeeper extension as well.

  • @erich2s
    @erich2s Před 7 měsíci +1

    next jotai tutorial please🥹

  • @tiavinarak7109
    @tiavinarak7109 Před 7 měsíci

    for state managment i prefer using preact/signal with contextAPI now, before i used redux toolkit

  • @yell4460
    @yell4460 Před 7 měsíci

    Hi great video, btw may I know what extensions are you using? Thankssss

  • @djarma7980
    @djarma7980 Před 6 měsíci

    Which extension is on Visual, when you typeing something, you see helper code that you Can write?

  • @killswitch.
    @killswitch. Před 7 měsíci

    Yesssss

  • @bryandelacruz9066
    @bryandelacruz9066 Před 2 měsíci

    Do you have a tutorial of this without typescript?

  • @loribryant4999
    @loribryant4999 Před 3 měsíci

    Hey is there a developer tools for zustand like redux dev tools?

  • @hacer7097
    @hacer7097 Před 6 měsíci

    What is the extension that always suggests you how to complete your code?

  • @techzone2009
    @techzone2009 Před 6 měsíci

    It is similar to riverpod in Flutter. 😊

  • @radharaji4153
    @radharaji4153 Před 6 měsíci

    I can see the code suggestion while you code is that an extension ?

  • @Tesfamichael.G
    @Tesfamichael.G Před 6 měsíci +1

    Saw it twice. Nice Content. What about Jotai

  • @TheZahraTajKhan
    @TheZahraTajKhan Před 2 měsíci

    what is the VS extension that you use to suggest what to type next

  • @icoderdev
    @icoderdev Před 7 měsíci

  • @camstuart
    @camstuart Před 6 měsíci

    I’ve been enjoying your videos, but one thing i can’t figure out is how to combine zustand (or other sate solution) with react query. Or if that’s a good idea. Feels like it is. EG, i have an audio element, which needs central state management because i want to control it from multiple other components. But it also gets its urls for the audio stream from the backend. I’d love to see a video of how or if you use react query with client state!

    • @cosdensolutions
      @cosdensolutions  Před 6 měsíci +1

      I actually have a video planned on exactly that ☺️

    • @camstuart
      @camstuart Před 6 měsíci

      @@cosdensolutions looking forward to it! I have subscribed

  • @ROVAKAN
    @ROVAKAN Před 7 měsíci

    how about client has a potato internet and it takes more than 1 second to retrive data from API ?

  • @ekchills6948
    @ekchills6948 Před 7 měsíci

    Cosden i have a question. Why zustand and not redux toolkit pls can you shed more light?

  • @faisal_dev951
    @faisal_dev951 Před 7 měsíci +1

    what if we have to persist state with localStorage then how to do ?

  • @rohithn-76
    @rohithn-76 Před 4 měsíci

    Will Zustand replaces redux !! Can we create Ecommerce project using Mern With Zustand state managment library

  • @khizer3528
    @khizer3528 Před 7 měsíci

    I am planning to use Zustand in one of my client's app. The app will be huge in terms of features and modules so I was confused whether should I go with Zustand or should I keep stick with Redux ? Any experience developer please share your experience

    • @cosdensolutions
      @cosdensolutions  Před 7 měsíci

      they're both great. Redux scales really well and I've used in complex apps. Zustand I haven't so I can't speak for it in that way. I would try to find if there's any specific features you need from one or the other that the other lacks, and use that as direction