Zustand - Complete Tutorial

Поділитися
Вставка
  • Опубліковано 17 гру 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!

КОМЕНТАРІ • 182

  • @xanteI
    @xanteI 5 місяців тому +52

    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  5 місяців тому +13

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

    • @user-qq8ms6dp7e
      @user-qq8ms6dp7e 5 місяців тому

      hey, could you link this?

    • @rodjenihm
      @rodjenihm 4 місяці тому

      @@user-qq8ms6dp7e Google "Slices pattern Zustand"

    • @xanteI
      @xanteI 3 місяці тому

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

    • @venicebeachsurfer
      @venicebeachsurfer 3 місяці тому

      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 3 місяці тому +8

    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 5 місяців тому +6

    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 5 місяців тому +10

    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 5 місяців тому +7

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

  • @r34ct4
    @r34ct4 4 місяці тому +1

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

  • @alkadoHs
    @alkadoHs 5 місяців тому +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 😎

  • @someone-on-earth
    @someone-on-earth 20 днів тому +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

  • @aryansuvarna4923
    @aryansuvarna4923 5 місяців тому +3

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

  • @VladyslavDihtiarenko
    @VladyslavDihtiarenko 4 місяці тому +3

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

  • @rameezh88
    @rameezh88 5 місяців тому

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

  • @camilo5821
    @camilo5821 5 місяців тому +1

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

  • @TannerBarcelos
    @TannerBarcelos 5 місяців тому +1

    Zustand is amazing. So light, simple and powerful.

  • @cslearn3044
    @cslearn3044 5 місяців тому +2

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

  • @nickwithaz
    @nickwithaz 3 місяці тому

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

  • @ToumaRenshi
    @ToumaRenshi 2 місяці тому

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

  • @letaciogalvao9908
    @letaciogalvao9908 3 місяці тому

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

  • @freeshorts4423
    @freeshorts4423 5 місяців тому

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

  • @Deepakkumar431
    @Deepakkumar431 5 місяців тому +1

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

  • @tomasburian6550
    @tomasburian6550 5 місяців тому

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

  • @gmjitendra
    @gmjitendra 5 місяців тому

    One more excellent learning. Thank you so much.

  • @OmarAmeen-sb8bt
    @OmarAmeen-sb8bt 4 місяці тому

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

  • @larrymcfarlane6202
    @larrymcfarlane6202 3 місяці тому

    Concise and to the point. Thanks!

  • @giovanio.3581
    @giovanio.3581 4 місяці тому

    Thanks for the tutorial, It was very easy to understand

  • @rohitghadage3220
    @rohitghadage3220 5 місяців тому

    You are one of the best UA-camr✨

  • @peterng.
    @peterng. 4 місяці тому

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

  • @uncore_
    @uncore_ 5 місяців тому +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 3 місяці тому

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

  • @_ayush_oswal
    @_ayush_oswal 3 місяці тому

    Really concise and easy to follow!!

  • @TheFatafillo
    @TheFatafillo 5 місяців тому +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.

  • @jeetdesaimusic
    @jeetdesaimusic 7 днів тому

    Amazing Explanation sir!

  • @0ninetyseven97
    @0ninetyseven97 5 місяців тому

    this gut deserves a million subs

  • @dukeselwood
    @dukeselwood 2 місяці тому

    Excellent tutorial, thanks

  • @zerdnelemo
    @zerdnelemo 2 місяці тому

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

  • @Ameer_Ameen
    @Ameer_Ameen Місяць тому

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

  • @chrishanthacosta4093
    @chrishanthacosta4093 3 місяці тому

    best zustand video..thanks

  • @rdx86
    @rdx86 19 днів тому

    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.

  • @arghyadas4138
    @arghyadas4138 4 місяці тому

    Great content
    Subscribed 🙌

  • @user-xu9tb7oe2z
    @user-xu9tb7oe2z 3 місяці тому

    brilliant education work! thanks!

  • @nfaical3
    @nfaical3 5 місяців тому +1

    Thanks 👍, nice explanation

  • @hanspen5978
    @hanspen5978 5 місяців тому

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

  • @omaracelys3217
    @omaracelys3217 5 місяців тому

    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

  • @minusmarigold98
    @minusmarigold98 3 місяці тому

    man , you are really best!

  • @Ksahdia
    @Ksahdia 5 місяців тому

    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!

    • @cosdensolutions
      @cosdensolutions  5 місяців тому

      Hahahahaha this killed me 😂

    • @Ksahdia
      @Ksahdia 5 місяців тому

      @@cosdensolutions :D

  • @felix_nope
    @felix_nope 2 місяці тому

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

  • @Jaracara11
    @Jaracara11 4 місяці тому

    Excellent video!

  • @rogeert
    @rogeert 5 місяців тому +4

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

  • @lutzruhmann7162
    @lutzruhmann7162 4 місяці тому

    This was very helpfull, Thanks!

  • @koleen3799
    @koleen3799 2 дні тому

    Thanks a lot, mate! 🎉

  • @harag9
    @harag9 5 місяців тому +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 5 місяців тому

      Redux is like a dinosaur..

    • @cosdensolutions
      @cosdensolutions  5 місяців тому +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!

  • @lucasyang7726
    @lucasyang7726 5 місяців тому

    Great video🎉

  • @fabianopereira1011
    @fabianopereira1011 4 місяці тому

    Obrigado, me ajudou muito.

  • @flwi
    @flwi Місяць тому

    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.

  • @thatsenoughdixit
    @thatsenoughdixit 3 місяці тому

    Love thisss

  • @mrvfino
    @mrvfino 3 місяці тому

    Thanks!

  • @gowthamsrinivasan9285
    @gowthamsrinivasan9285 5 місяців тому

    Great video

  • @joerodrigo9661
    @joerodrigo9661 4 місяці тому

    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?

  • @user-qq8ms6dp7e
    @user-qq8ms6dp7e 5 місяців тому +1

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

    • @sep1ol
      @sep1ol 5 місяців тому

      i have the same question
      did you figure this out?

  • @Di-yes
    @Di-yes 5 місяців тому +1

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

    • @cosdensolutions
      @cosdensolutions  5 місяців тому +1

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

  • @lekandar4889
    @lekandar4889 5 місяців тому

    Thanks man

  • @Mrkostas7777ify
    @Mrkostas7777ify 5 місяців тому +1

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

  • @fernandosoaresdev
    @fernandosoaresdev 5 місяців тому

    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  5 місяців тому

      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 4 місяці тому

      @@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.

  • @SKKhandokar
    @SKKhandokar Місяць тому

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

  • @pixyoutube538
    @pixyoutube538 5 місяців тому

    Very helpful

  • @blankvoid4137
    @blankvoid4137 Місяць тому

    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?

  • @kousheralam8657
    @kousheralam8657 4 місяці тому

    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 ?

  • @milanzmitrovic
    @milanzmitrovic 4 місяці тому

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

  • @KylanHurt
    @KylanHurt 3 місяці тому

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

  • @battulabalakrishna8062
    @battulabalakrishna8062 4 місяці тому

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

  • @yell4460
    @yell4460 5 місяців тому

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

  • @saurabhu6458
    @saurabhu6458 5 місяців тому +1

    Please make video on signals😊

  • @bryandelacruz9066
    @bryandelacruz9066 Місяць тому

    Do you have a tutorial of this without typescript?

  • @patrickmichael4113
    @patrickmichael4113 5 місяців тому

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

  • @loribryant4999
    @loribryant4999 2 місяці тому

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

  • @tiavinarak7109
    @tiavinarak7109 5 місяців тому

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

  • @erich2s
    @erich2s 5 місяців тому +1

    next jotai tutorial please🥹

  • @techzone2009
    @techzone2009 4 місяці тому

    It is similar to riverpod in Flutter. 😊

  • @djarma7980
    @djarma7980 4 місяці тому

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

  • @hacer7097
    @hacer7097 4 місяці тому

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

  • @camstuart
    @camstuart 4 місяці тому

    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  4 місяці тому +1

      I actually have a video planned on exactly that ☺️

    • @camstuart
      @camstuart 4 місяці тому

      @@cosdensolutions looking forward to it! I have subscribed

  • @khizer3528
    @khizer3528 5 місяців тому

    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  5 місяців тому

      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

  • @radharaji4153
    @radharaji4153 4 місяці тому

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

  • @killswitch.
    @killswitch. 5 місяців тому

    Yesssss

  • @TheZahraTajKhan
    @TheZahraTajKhan 18 днів тому

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

  • @Tesfamichael.G
    @Tesfamichael.G 5 місяців тому +1

    Saw it twice. Nice Content. What about Jotai

  • @faisal_dev951
    @faisal_dev951 5 місяців тому +1

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

  • @rohithn-76
    @rohithn-76 3 місяці тому

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

  • @bakersentamu4725
    @bakersentamu4725 4 місяці тому

    How zustand is this easy, Always felt redux tool kit was too bulky

  • @ROVAKAN
    @ROVAKAN 5 місяців тому

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

  • @henochangemichaellonzokoff6036
    @henochangemichaellonzokoff6036 5 місяців тому

    Can we find out how to manage persistence and advanced concepts in real cases, as well as best practice in react?

    • @cosdensolutions
      @cosdensolutions  5 місяців тому +1

      This was meant to be a beginner tutorial! For persistence it's actually simple, check out the docs for the persist middleware. For best practices, I have 2 at the end that should be great to get you going

    • @henochangemichaellonzokoff6036
      @henochangemichaellonzokoff6036 5 місяців тому

      @@cosdensolutions Thank you for everything. I'm following you from the Ivory Coast.

  • @ekchills6948
    @ekchills6948 5 місяців тому

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

  • @icoderdev
    @icoderdev 5 місяців тому

  • @davidgibradze9692
    @davidgibradze9692 5 місяців тому

    Video about signals , vs hooks

  • @_Yolandi
    @_Yolandi 4 місяці тому

    Me as a german speaker crying everytime he says Zustand wrong.

  • @ptolemyhenson6838
    @ptolemyhenson6838 5 місяців тому +13

    I don't see the point in using Zustand as opposed to just creating a regular JavaScript class with these functions as members and then providing an instance as context so individual components can access the state and modify it as needed. Then, the instance could be provided as a parameter to an external function to get the same functionality shown in the video.

    • @piscopancer
      @piscopancer 5 місяців тому +4

      Yeah it seems you described the whole thing Zustang does😂

    • @ptolemyhenson6838
      @ptolemyhenson6838 5 місяців тому +6

      @@piscopancer There is one thing, I think. It seems like Zustang allows a component to be dependent only on one singular property instead of the whole state. I guess that could be used if the state is complicated and the unnecessary renderings are causing performance issues.

    • @piscopancer
      @piscopancer 5 місяців тому +2

      @@ptolemyhenson6838 oh I see. Honestly, that's a big optimisation work offered by Zustand thought. Makes it reasonable then

    • @DarrylHebbes
      @DarrylHebbes 5 місяців тому +2

      Exactly, if wrote a class that does this you effectively Write Zustand, but don’t forget it has a pub sub feature, hooks and a design that fits the react idiom.

    • @samuelswatson
      @samuelswatson 5 місяців тому +3

      That doesn’t work because the attribute updates don’t trigger React updates. The library valtio implements this approach in a way that does hook into React, though.

  • @kale_bhai
    @kale_bhai 5 місяців тому +1

    Next video, React Context API with useReducer

  • @endlessia
    @endlessia 5 місяців тому +1

    Is there a lovely person who can show a github project using Zustand ? I want to see how to structure an app with Zustand, like should I split stores

    • @Iandavidandrino
      @Iandavidandrino 5 місяців тому +1

      I like to do a folder (& @ my job)
      store /
      - user
      - etc

  • @malczag9928
    @malczag9928 3 місяці тому

    what extension is this with hints?

  • @CoryTheSimmons
    @CoryTheSimmons 5 місяців тому

    Valtio is just simpler and better, right?

  • @xxXAsuraXxx
    @xxXAsuraXxx 5 місяців тому +1

    Redux toolkit is awesome as well with RTK query