Global State Management in NextJs 14 Using Zustand

Поділитися
Вставка
  • Опубліковано 25 сер 2024

КОМЕНТАРІ • 102

  • @kamaliddinsattorov7493
    @kamaliddinsattorov7493 9 місяців тому +13

    You're probably the best guy to teach web dev. Thanks for the effort you put in to spread knowledge.

    • @hamedbahram
      @hamedbahram  9 місяців тому +2

      My pleasure! Glad you think so.

    • @wibbs88
      @wibbs88 7 місяців тому

      I agree! Great teaching style. Looking forward to more content in 24.

    • @hamedbahram
      @hamedbahram  7 місяців тому

      @@wibbs88 Thanks! for sure!

  • @kyle-andrewgovinder9902
    @kyle-andrewgovinder9902 9 місяців тому +11

    When I see this handsome man smiling on a thumbnail, I already know that I'm about to get even better at using Nextjs

    • @hamedbahram
      @hamedbahram  9 місяців тому

      Thanks Kyle 😎 I appreciate that!

  • @victormustin2547
    @victormustin2547 9 місяців тому +7

    zustand is so good and simple I love it

  • @imkir4n
    @imkir4n 9 місяців тому +5

    What a surprise hamed! I was doing the same Kanban board task too. Cool

  • @codingwithlucy
    @codingwithlucy 9 місяців тому +8

    Thanks so much, this was so useful and great you uploaded it exactly on the day that I needed to check out Zustand for Next 14 🤣🙏🏻

    • @hamedbahram
      @hamedbahram  9 місяців тому

      My pleasure! Glad it was useful! Right on schedule 😅

  • @cosmo-rodrigues
    @cosmo-rodrigues 4 місяці тому +2

    Man, I have no words to say thank you. Cheers from Brazil!

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

      My pleasure, man! I appreciate it.

  • @rohan-motukuri
    @rohan-motukuri 6 місяців тому +3

    Banger! Thank you for your consistent hardwork

    • @hamedbahram
      @hamedbahram  6 місяців тому

      My pleasure! I appreciate that.

  • @kellslte
    @kellslte 3 місяці тому +1

    This has gotten me started on using global state in a Next.js app. Your tutorials are straight to the point and full of wisdom! Thank you for this awesome tutorial. Could you do a tutorial on complex datatables with shadcn tables using zustand as state manager?

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

      I'm glad you've found the videos useful. You can watch this video for data tables → ua-cam.com/video/kHfDLN9w1KQ/v-deo.html

  • @MrZiyak99
    @MrZiyak99 9 місяців тому +2

    great vid i feel like this is a perfect usecase for the useOptimistic hook where you can then persist your data on the server instead of the client

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

    awesome tutorial. i have learnt a lot of new things from you here. it was a little bit difficult but i am gonna do for myself from scratch soon to get better, thank you !

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

      My pleasure! Glad it was helpful.

  • @VincentFulco
    @VincentFulco 9 місяців тому +3

    Terrific topic and tutorial. Thanks

    • @hamedbahram
      @hamedbahram  9 місяців тому

      Appreciate it! Glad it was helpful!

  • @Fanaro
    @Fanaro 3 місяці тому +1

    Your tutorials are very helpful, thank you.

  • @smashmash3455
    @smashmash3455 9 місяців тому +1

    Thanks a lot for the video. It helped me setup persistent zustand.

  • @sergheic31
    @sergheic31 6 місяців тому +1

    superb tutorial, as all your content is! thank you!

    • @hamedbahram
      @hamedbahram  6 місяців тому

      You're welcome! I appreciate that.

  • @AyanGhosh-vj7ui
    @AyanGhosh-vj7ui 4 місяці тому +1

    Thank you so much, this was so helpful ❤

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

      You're welcome! I'm glad it was helpful.

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

    I want to thank you for your high quality toturials .
    Generally I dont like to use typescript and I am trying to do it without typescript when watching any toturials, I wish I could find project that do not use typescript which is not all beginners

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

      You're welcome. I totally understand, TS makes it more complex for beginners. I have a lot of JS videos as well, but recently doing more TS.

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

      @@hamedbahram as a beginner I am involving lots of lanuages from Motoko to Solidy from python to Javacript and Rust and learning a new TypeScript is another headache for me I think I will never be able to be a real developer if I dont limit myself with just a couple of them, maybe I am wrong, actually I cant stop myself watching your videos you are a very good in the way you teach.

  • @danijeldzakula8709
    @danijeldzakula8709 7 місяців тому +1

    Thanks a lot for the video 🖐

  • @kiefer8101
    @kiefer8101 8 місяців тому +1

    great stuff!

    • @hamedbahram
      @hamedbahram  8 місяців тому

      Thanks! Appreciate that.

  • @SaMi-kv6yi
    @SaMi-kv6yi 4 місяці тому +1

    That's great, exactly what I was looking for, and besides, can you tell me the "fontFamily" of vsCode in the video?

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

      Glad to hear that. The font is called Operator mono.

  • @FuzzyAnkles
    @FuzzyAnkles 16 днів тому

    great content!

  • @kianooshsoleimani5472
    @kianooshsoleimani5472 4 місяці тому +2

    dear hamed, please if it is possible made a video about showing notification or something in the form server actions ...

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

      For sure! I've done it in some of the projects related to server actions, but I'll have that in mind.

  • @mathiasriissorensen6994
    @mathiasriissorensen6994 6 місяців тому +2

    This was brilliant and I learned a lot. Thank you!
    How can we connect the store with a database?

    • @hamedbahram
      @hamedbahram  6 місяців тому

      Glad to hear that! You're welcome.
      You can use a middleware to persist state, read more here → docs.pmnd.rs/zustand/integrations/persisting-store-data

    • @mathiasriissorensen6994
      @mathiasriissorensen6994 6 місяців тому +1

      Thank you! 🙏🏼@@hamedbahram

  • @ahmedabdelrahman4034
    @ahmedabdelrahman4034 6 днів тому +1

    but with such a setup in nextjs, you create store on each request
    the optimal setup is to use provider and assign store to useRef and then chack if store assigned to the ref or not to prevent creating store on each request

    • @hamedbahram
      @hamedbahram  6 днів тому

      Valid point. The new pattern is an addition to the zustand docs after the time of this recording.

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

    Nice content! Thanks

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

      Thank you! I appreciate that.

  • @simonaedwards
    @simonaedwards 2 місяці тому +2

    Hey Hamed, Zustand Docs now have an entire new section "Setup with Next.js" which seems to have way more boilerplate code then described in your great tutorial.
    How does this new requirement impact your example? Is it still valid?

    • @hamedbahram
      @hamedbahram  2 місяці тому +2

      Thanks for noting that, I looked at it and it's a bit different from our implementation in that it shares the store via context. I'd have dig a bit deeper to understand why this is.

  • @sagarchilivery6112
    @sagarchilivery6112 9 місяців тому +1

    I wish it had cool drag and drop animation like react-beautiful-dnd

    • @hamedbahram
      @hamedbahram  9 місяців тому +4

      That'll be for the part II of this video :)

  • @marcosduong
    @marcosduong 9 місяців тому +1

    Amazing!!

    • @hamedbahram
      @hamedbahram  9 місяців тому +1

      Thank you.

    • @marcosduong
      @marcosduong 9 місяців тому +1

      Keep going. I have learned a lot of knowledge from your channel. Thank you very much, Hamed Bahram !!🎉

    • @hamedbahram
      @hamedbahram  9 місяців тому

      @@marcosduong I appreciate that Marcos.

  • @davidetrevisan7603
    @davidetrevisan7603 Місяць тому +1

    Hello, you need to wrap the store with context otherwise you share what inside the store with different user. Check the docs...

    • @hamedbahram
      @hamedbahram  Місяць тому +1

      That wasn't the case at the time of this recording; However, there is a new update in the way Zustand works and should be implemented in NextJs.

  • @mobinans8558
    @mobinans8558 9 місяців тому +1

    Awesome

  • @LucianoSoares85
    @LucianoSoares85 15 днів тому +1

    What about the NextJS recommendation from the zustand documentation? There they use React Context with zustand. Is that not necessary?

    • @hamedbahram
      @hamedbahram  15 днів тому

      That's a new addition to the docs after the time of this recording. I would follow the docs. I will make an updated video at some point discussing it later.

  • @aguud
    @aguud 8 місяців тому +1

    nice video

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

    Not to distract from the incredible video and explanation of this all, but what theme or config does your vsCode have that gives you the cursive fonts on keywords?

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

      Hey, no worries! I’m using Dark+ Italic theme and my font is Operator mono.

  • @deepeshsharma7508
    @deepeshsharma7508 7 місяців тому +1

    Thanks buddy this was great video but i have a doubt that when you fetch data from an API on SSC and you want to send that data to store at that point we cant use any hook on SSC how could we do that ?

    • @hamedbahram
      @hamedbahram  7 місяців тому

      I'm not sure if I understood the question! What did you mean by SSC?

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

    everythign is perfect, thank you for your video. The only question that comes to my mind is: Do you actually need typescript? There are good features from ts that could really help in big projects with types etc. but I noticed that you are doing sometimes too much extra work. Instead of just throw some children to the component, you have to go and define them as node or something else. Is it really that necessary for the real project?

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

      Thank you! I agree TS adds some overhead when developing but it ultimately pays off when catching potential bugs in your code before deploying.

  • @WatashiwaWatashi-zw7hy
    @WatashiwaWatashi-zw7hy 5 місяців тому +1

    Hi why in my side the state is late to update ya? I mean when I refresh the page the data is still empty but in a second the data would be appear. so maybe it will be trouble later

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

      Not sure why that is, clone my code and compare to yours to see what you're doing differently.

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

    Do you think the App Router is still a good choice for apps that don't do any server stuff themselves? Like connecting to an external BFF and interacting with it through client components?

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

      Absolutely! First of all, the app router is not just for using server components, there is nothing wrong with using client components at all. Secondly, even client-side apps have parts that are static and can be served from the server like layouts, with new features like partial pre-rendering I think the app router is the way to go no matter what.

  • @ambiguity1768
    @ambiguity1768 Місяць тому +1

    I'm new and I ran into a problem where Header should be a server component because I need to use another server component (ShoppingCart) inside the client component and because of this absolutely everything is marked as dynamic after the build, is this a bad practice?

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

      Using server components doesn't mean dynamic unless you're using dynamic functions such as `cookies` and `headers` which are request specific. I can't really judge if you're implementation is good or bad with this limited knowledge.

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

      @hamedbahram
      I use a session-based shopping cart cause I do not have user authentication, and it was the only way to save cart data after closing the browser.
      And it looks like this:
      (server component as it's async)
      (client component)

  • @nvictorme
    @nvictorme 9 місяців тому +1

    Honest question: why do you need a client side state manager (Zustand) whilst using an RSC based framework?

    • @hamedbahram
      @hamedbahram  9 місяців тому +1

      Good question! You don't necessarily need a client-side state manager.

    • @nvictorme
      @nvictorme 9 місяців тому +1

      I might be missing the use-case for this. Maybe for ephemeral states like order items in a shopping cart or product customization.

    • @hamedbahram
      @hamedbahram  9 місяців тому

      @@nvictorme Yes that can be the usecase.

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

    thanks for video.
    i feel like web development experience for csr + ssr is quite complex and confusing.
    it's certain that next 14 isn't the perfect tool

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

      Don't think of it as csr or ssr, think in terms of what you want to build, the functionality you want to have , and let the tool take care of the underlying details. I think NextJs 14 is awesome.

  • @raghavdholu302
    @raghavdholu302 9 місяців тому +1

    really loved your exlpanatoin. also how can i get that font for my vscode

    • @hamedbahram
      @hamedbahram  9 місяців тому

      Thanks! The font is Operator mono.

  • @mohdsahil226
    @mohdsahil226 9 місяців тому +1

    Thanks again for a great tutorial. Would you please make a video on Typescript in Next.js. There is no tutorial which tell how to setup typescript lint in nexj.js.
    event if I remove the type and run lint. it doesn't catch the typescript type error. Would you please help?

    • @hamedbahram
      @hamedbahram  9 місяців тому

      I do have a video on TS → ua-cam.com/video/XmWGqi0pskU/v-deo.htmlsi=yfWsKS-VS-nLG2SS

  • @atifali3485
    @atifali3485 8 місяців тому +1

    hi i was creating something similar using context api, so i get hydration error on initial load coz on my client side data rendered based on localStage value.. how do i fix?

    • @hamedbahram
      @hamedbahram  8 місяців тому

      Read your local storage inside `useEffect`

  • @AyanGhosh-vj7ui
    @AyanGhosh-vj7ui 4 місяці тому

  • @alirezarezaei7416
    @alirezarezaei7416 8 місяців тому

    Thanks a lot. why we should use Next js for this applications? i think Next js is not a good choice for this application

    • @hamedbahram
      @hamedbahram  8 місяців тому

      This video shows how to use global state management in NextJs. You can use whatever you feel better suited.

    • @alirezarezaei7416
      @alirezarezaei7416 8 місяців тому

      but it was better to choose a project that make sense to use NextJS@@hamedbahram

  • @gurpreetsingh-pf4ms
    @gurpreetsingh-pf4ms 9 місяців тому

    What about if i want to use redux for state management?

    • @hamedbahram
      @hamedbahram  9 місяців тому

      It'd be pretty similar to this.