This Makes State Management so Much Easier

  Рет қаралды 101,762

Josh tried coding

Josh tried coding

Күн бұрын

Пікірлер: 175
@thesunabsolute
@thesunabsolute Жыл бұрын
I knew this video was about zustand just from the title lol
@trestres4151
@trestres4151 Жыл бұрын
Same lol
@adityaj21
@adityaj21 Жыл бұрын
same
@joshtriedcoding
@joshtriedcoding Жыл бұрын
Seems like you've been watching some previous videos then. Appreciate ya man.
@8koi245
@8koi245 Жыл бұрын
Hahaha ikr it's just too good
@breakinggood-r2v
@breakinggood-r2v Жыл бұрын
Same thoughts lol
@remongrabu
@remongrabu Жыл бұрын
Hope you make more vids about Zustand and showcase more complex real world use cases! This library deserves more exposure but their docs are a mess tbh. They’re also considering removing the “create” api in v5 according to a discussion in their GitHub repository
@joshtriedcoding
@joshtriedcoding Жыл бұрын
Interesting! Might just do that! Tried Zustand out half a year ago and just came back to it like a week before I made this video. It felt so refreshing and intuitive compared to context. Definitely some more advanced use cases you could do with this, the challenge is wrapping them into an easy to understand/follow video haha
@belkocik
@belkocik Жыл бұрын
​@@joshtriedcoding I would love to see Zustand Crash Course in your channel as well (combinated with react query to fetch data to your store, e.g handle logging/registering a user to an app). Cheers! :)
@marcelomagalhaes4508
@marcelomagalhaes4508 Жыл бұрын
Using zustand is as complicated as the video shows. The video could just show a get example, but it's just "get().variable". It can't be easier to use than this!
@ayushjain7023
@ayushjain7023 Жыл бұрын
Zustand + React query === Right way to do State management ❤
@thecarpenter_son
@thecarpenter_son Жыл бұрын
I think for most use cases jotai is better than zustand for the simplicity. It just feels like global useState while zustand is good if u have a lot of actions in a store and you want it access the value outside of react
@truongbuipv
@truongbuipv Жыл бұрын
How about recoiljs, should I use which one?
@justin.johnson
@justin.johnson Жыл бұрын
That's backwards
@moh6823
@moh6823 Жыл бұрын
Although it is okay to use destructuring when you are retrieving data from the store, you should be wary for when you want your component to re-render. If you destructure you are getting retrieving all the store, meaning if something changed, the component will rerender. If you want a better alternative, use selectors.
@franciskintungi
@franciskintungi Жыл бұрын
Show example please
@syncmaster320
@syncmaster320 Жыл бұрын
Yes, you're right. Destructuring the way shown in the video subscribes to the whole store resulting in re-renders whenever any state in the store changes.
@kamehameha38
@kamehameha38 Жыл бұрын
What if you have only one state in the store? Is there still any benefit of using a selector?
@spicynoodle7419
@spicynoodle7419 Жыл бұрын
​@@franciskintungi const user = useStore(state => state.user) const [user, roles] = useStore(state => [state.user, state.roles])
@spicynoodle7419
@spicynoodle7419 Жыл бұрын
​@@kamehameha38you almost always store multiple things in a global store, unlike useState. So if you decide to add a new variable you have to go back to all components and change to selectors... or just live with 2-3x slower rendering and more API requests due to unnecessary re-renders.
@jawyor-k3t
@jawyor-k3t Жыл бұрын
zustand is a godsend lib. it's so elegant and tiny. great interface too. i discovered it earlier this year and it's really enjoyable
@agus-wesly
@agus-wesly Жыл бұрын
jotai is awesome too, no provider needed also and they are using interesting approach called atom
@rog0079
@rog0079 Жыл бұрын
Hi, great video! Could you make a proper video specifically on zustand, best practices, managing auth state, scalable folder structure, hydrating the state etc. It would be really great as there aren't many tutorials on this.
@itssammy777
@itssammy777 Жыл бұрын
One of the greatest things about zustand is that It can manage state outside react, so If you want for example to store data via a function that is not a inside a component, and then consume it inside another function totally different, you can totally do it, without react yelling at you for trying to use reactive state outside components.
@filipjnc
@filipjnc Жыл бұрын
I love jotai just as much as zustand. It’s from the same devs too.
@quentinfrancois690
@quentinfrancois690 Жыл бұрын
Great vid as usual, a next one with a real use case of Zustand could be awsome. A pleasure to have new Josh content every week. ❤
@officialabdulrehman
@officialabdulrehman Жыл бұрын
Your explanations are really easy to understand!
@joshtriedcoding
@joshtriedcoding Жыл бұрын
Cheers man, that's very nice to hear. Means a lot.
@velkb228
@velkb228 8 ай бұрын
DUDE. THANKS.
@daskasspatzle2396
@daskasspatzle2396 Жыл бұрын
Just waiting for the Ausnahmezustand. Thanks for sharing, will give it a try.
@honestslave
@honestslave Жыл бұрын
Wow, your videos are always so helpful! I have a new video request - could you make a video on how to use React-hook-form with TinyMCE (Rich Text Editor) on Submit, along with the other input fields? It would be amazing to see you tackle this topic and help us all level up our skills. Best of luck 🎉!
@joshtriedcoding
@joshtriedcoding Жыл бұрын
Cheers man! Seems like a very specific use case for an issue you might be having? Never tried TinyMCE to be honest, just slate and editorjs
@honestslave
@honestslave Жыл бұрын
@@joshtriedcoding So then Any Kind of Rich Text Editor with react-hook-form On Submit
@rand0mtv660
@rand0mtv660 Жыл бұрын
You just have to either use register() to register the field and then do whatever you want with it or just wrap it in a Controller component as with any other custom form element that cannot just use register() easily out of the box. It's more simple than you think.
@dg1h1t
@dg1h1t Жыл бұрын
great solution. I wish next team came up with an easy solution to manage state in their apps
@_y7ya
@_y7ya Жыл бұрын
I heard before that destructuring on Zustand like you did in 3:31 is not recommended as it causes rerenders?
@syncmaster320
@syncmaster320 Жыл бұрын
Yes, you end up subscribing to the whole store which causes re-renders whenever any state changes in the store.
@qazyhn94
@qazyhn94 Жыл бұрын
Yes it's true in their docs they say the same and it makes it less cleaner sad
@mfpears
@mfpears Жыл бұрын
I don't get why context providers are hard. You provide them once, or your team lead does, and that's it. Years of development without touching it again.
@freeguy2418
@freeguy2418 Жыл бұрын
Quick but Best Explanation! I like zustand for it's simplicity
@Rasty_Boss
@Rasty_Boss Жыл бұрын
when new project with zustand ?
@kiddasneve1677
@kiddasneve1677 Жыл бұрын
your content just blow my mind, thanks. U r awesome!
@4ndrs_dev
@4ndrs_dev Жыл бұрын
This came out just as I was starting to learn Zustand ❤
@jettisonjj
@jettisonjj Жыл бұрын
I hope you make more videos about zustand. You're awesome at this! I'm a fan ❤️
@kratos_respawned
@kratos_respawned Жыл бұрын
Thank you for sharing this , can you please make an in depth tutorial on zustand , how to use middlewares in zustand, async state etc
@dan110024
@dan110024 10 ай бұрын
I just spent two days implementing react's context into my app. I figured I need to know why people dislike it so much before passing it off. Safe to say that it got very messy. I can't believe how easy zustand is now lol.
@mudgalz
@mudgalz Жыл бұрын
zustand made state management in simple usestate like hooks, so damn amazing
@BeyondLegendary
@BeyondLegendary Жыл бұрын
Impressive, very nice. Let's see Paul Allen's state management.
@satadeepdasgupta397
@satadeepdasgupta397 Жыл бұрын
Zustand and Jotai are my goto state-management Libraries
@captainlennysub
@captainlennysub 10 ай бұрын
Man I love your videos. Thank you so much for this.
@Finefik
@Finefik 8 ай бұрын
Love your zustand pronaunciation
@rahimco-su3sc
@rahimco-su3sc Жыл бұрын
you are making the web easy ! thanks a lot josh
@ragtop63
@ragtop63 Ай бұрын
The original statement is misleading. The example might not show it but you can absolutely modify the state from any of the descendant components under the context provider. You just include the state modifier as part of an object in the provider’s ’value’ property. After that, destructure the object in any descendant component and you have access to it. And the best things is, you only have to destructure the properties you need. It really doesn’t get any easier than that and it’s much easier than having to learn a whole new API since most of the operations you’ll be performing are written in plain JavaScript/TypeScript.
@joostschuur
@joostschuur Жыл бұрын
Josh casually teaching thousands of devs how to pronounce 'Zustand'!.;)
@one2treifor
@one2treifor Жыл бұрын
It all looks nice and fresh, but I would really be careful with the count of libraries I use, dependency grows, maintainability becomes more difficult. Of course its good to know about this library, and small projects can def make use of it.
@curiouslycory
@curiouslycory 7 ай бұрын
I've been thinking about doing more of this and your video really helps me narrow my thinking on how to implement! Thanks for sharing! Is the thing that tells you the size of your import a vs code extension? That looks super helpful!
@elbjorno
@elbjorno Жыл бұрын
With Jotai (same creator as Zustand) handlig global state is even simpler. You should try it out and make a video about it. Its gonna blow your mind i promise!
@Euquila
@Euquila Жыл бұрын
React context was never meant to be a statement manager. It's simply a means of passing context down to children. For example, say you are implementing the renderCell function in a MUI GridColDef --- you can simply useContext to teleport data or pass context down from a great-great-great-....-ancestor without having to worry how to pass the props through a MUI jungle of relationships
@Leyksnal
@Leyksnal Жыл бұрын
Honestly this lib is a game changer and ever since i started using it , i am not leaving it soon
@SerenModz21
@SerenModz21 Жыл бұрын
have you ever tried Jotai? that seems like another great alterative
@N3mo_Ahead
@N3mo_Ahead Жыл бұрын
I havent seen much from zustand by now, but how does it compare to Recoil? It seems kind of similiar.
@jrdn5206
@jrdn5206 Жыл бұрын
I prefer state setters to live as exported functions where state is and not destructure. Keeps state state and actions. I believe they recommend this in the docs too.
@wezter96
@wezter96 10 ай бұрын
Have you considered making a video on Legend State? Feels like one of the first real options for fine grained reactivity control in the React ecosystem🤔
@skyzane2735
@skyzane2735 8 ай бұрын
Where is that documentations can be found? Any links? 0:20
@trentcox9239
@trentcox9239 Жыл бұрын
with zustand though, if i have a complex component that uses zustand to inject state into deep child components...but i have that complex component rendered more than once on the same page (lets say its a chart with an interactive legend or something), will that work? wont each component behave unexpectedly because they're both deriving state from the same global store?
@LegendaryAks
@LegendaryAks Жыл бұрын
Great video Josh love your content, I have question if you if you use this library or context api on page refresh the value resets. Currently localstorage was a option i found is ther any other workaround it
@tmoumimahmoud6966
@tmoumimahmoud6966 6 ай бұрын
Thank you, Can I use it for getting connected user info from the cookies ??
@hazemkawas669
@hazemkawas669 Жыл бұрын
Thanks a lot, but why i get an error and tell me to change to client component??
@appstuff6565
@appstuff6565 Жыл бұрын
hey josh thanks for this! Im using zustand but not able to persist server (setstate) to server component (getstate), the store doesnt just persist among SERVER components. Do you know what the issue is since we cant directly use hooks to set in server side? I console.log it and it says UNDEFINED.
@appstuff6565
@appstuff6565 Жыл бұрын
it does persist in the same server component (root page.tsx) that i persist it in, but in another server component it becomes undefined.
@tmoumimahmoud6966
@tmoumimahmoud6966 6 ай бұрын
Thank you , but I have a question and sorry if I seem stupid: suppose that in my application after the user logged in , can I use the state management here (talking about the old way with useContext) to save the return of backend call /api/findUserById/${id}, because I have many pages in my nextjs that need the profile picture and other user info , so I am currently calling the findUserById in those all pages , which is dump ? Thank you in advance.
@ichigokuro3986
@ichigokuro3986 4 ай бұрын
did you find the answer to this?
@vince530
@vince530 Жыл бұрын
i subscribed, thankyou for this!
@qazyhn94
@qazyhn94 Жыл бұрын
I think just destructure from useState is not recommend, in their documentation they advise to make a new object with selected properties to prevent unnecessary rerenders
@onyekachijames1636
@onyekachijames1636 Жыл бұрын
does zustand work with server components or one has to do "use client" ?
@jamshediqbal7936
@jamshediqbal7936 Жыл бұрын
What’s the difference between type and interface in typescript?
@helleye311
@helleye311 Жыл бұрын
I love zustand, makes state so much nicer. I've practically eliminated context from my apps with this + react query (sure that has a context technically, but I mean, it's just one) Only downside I found for this is, you can't reuse contexts. At least not as far as I'm aware. You can say "from this point onward, use this stuff", so doing anything with forms or individual reusable components still requires standard context if you want to have multiple of them going at the same time. But these tend to be highly specialised, with only a few values passed down, so it's not the end of the world.
@joshtriedcoding
@joshtriedcoding Жыл бұрын
Very powerful combo you've got with react query and zustand. Not sure about the caveat you're talking about here, you mean there is a use case where you couldn't rely just on Zustand and needed context along with it?
@MrREALball
@MrREALball Жыл бұрын
@@joshtriedcoding Imagine a complex (with deeply nested elements) component that has to be reused across the app with different internal state (I know its a bad example, but imagine a form that rendered in different places in your app but if user fills it in one place, it shouldn't be filled in the other). To create it you could either use prop drilling or context, but can't use Zustand, since its stores act like singletons in an app.
@aBradAbroad
@aBradAbroad Жыл бұрын
@@MrREALball Interesting. I'm actually dealing with this issue right now, and so far I've just been using useState for those form components and using a setter to update the store with the submitted value. I'm not sure if this is an antipattern or what but it works ok. Would love to hear your response.
@AtizaJuanita
@AtizaJuanita Жыл бұрын
I wouldn't manage form states. Use React hook form instead and let it do it's magic
@helleye311
@helleye311 Жыл бұрын
@@AtizaJuanita yeah, but imagine your form is nested and you don't want to pass the form state though props. You can't use zustand to provide the react hook form setters. Not in a reusable way at least. You can however provide them with context. You can just useForm, pack the output into context and you're good to go for the entire thing. Implementing this at work is my next personal target, no one ever bothered with form libraries there so some components have 20 use states, when they could be useForm + local context
@LuckyImposter
@LuckyImposter Жыл бұрын
what kind of extension highlight the name and appear the description?
@samanderson4881
@samanderson4881 Жыл бұрын
cant wait for the next release of react to literally just be vue
@anhdunghisinh
@anhdunghisinh Жыл бұрын
If i implement zustand like this in a nextjs app, will there be any hydration error?
@abdullah_mufti
@abdullah_mufti Жыл бұрын
Thanks for sharing this library.. do u think we can use it in place of redux aswell?
@joshtriedcoding
@joshtriedcoding Жыл бұрын
Oh yeah for sure. Way more fun to use than redux
@Leyksnal
@Leyksnal Жыл бұрын
Try it and enjoy the simplicity
@shri_x1
@shri_x1 Жыл бұрын
Zustand is lit for real (3 months of using it ) its so f*ing good
@ashuvssut
@ashuvssut Жыл бұрын
zustand's for reducer based state management. Jotai for simple useState like state management. If I were to record this video, I would have done it using jotai
@anonymoussloth6687
@anonymoussloth6687 Жыл бұрын
Hi. Can you do a video with a roadmap for beginners in web dev. What topics, subjects, libraries, tools etc we should learn to become good full stack developers
@Septumsempra8818
@Septumsempra8818 Жыл бұрын
What should we consider when accessing state on server?
@kaas99
@kaas99 Жыл бұрын
I never made sense to me to use Redux. But Zustand, YES!
@gandalfthegrey2777
@gandalfthegrey2777 Жыл бұрын
It looks really awesome, I am planning to use zustand in my personal projects over context or redux. But I think there won't be any jobs asking for zustand, Most of them would want me to be proficient with redux right?
@joshtriedcoding
@joshtriedcoding Жыл бұрын
Redux is veeery widely used, especially in enterprise contexts. If you wanna go job hunting, I'd definitely recommend learning it. For my own projects I never use it anymore though
@moosegoose1282
@moosegoose1282 Жыл бұрын
doesn't work with nextjs without hacks, because zustand doesn't take in initial state, which ppl don't like when u have the state info but client takes a while to initlize
@mkroven
@mkroven Жыл бұрын
tsquery has isloading too?
@rmcodes
@rmcodes Жыл бұрын
Jotai seems much simpler to use imo. All of these tools work on the client though but I haven't found one that can better handle the server/client boundary issues (hydration) I've had when trying to use thing like user preferences etc. Maybe there is one out there but I haven't found it yet.
@LC12345
@LC12345 Жыл бұрын
This dude knows German. You can tell from the way he pronounced Zustand 😂
@StephanHoyer
@StephanHoyer Жыл бұрын
He is german, I think.
@ejoojoo
@ejoojoo Жыл бұрын
hope you can do a comparison with jotai
@saucyreaddit
@saucyreaddit Жыл бұрын
Hmm. How about your own version of an e-commerce app?
@Englishmusic-qi9fp
@Englishmusic-qi9fp Жыл бұрын
It's better than react context api. I really love the name
@marcelkrause-u4w
@marcelkrause-u4w 8 ай бұрын
Why don't you provide the context with a setter-function?
@furo.v
@furo.v Жыл бұрын
Lol... the classic "you don't need X to manage state anymore, use Y" meme
@fraciscro
@fraciscro 8 ай бұрын
Great one! Helpful!
@othman_
@othman_ Жыл бұрын
Josh we would love if you give surrealDB a review
@erassylzh5658
@erassylzh5658 Жыл бұрын
Is it make sense to use both jotai and zustand together?
@rayramadita3018
@rayramadita3018 Жыл бұрын
Hi Josh! What do you think about jotai as a state manager? Have you been used it?
@joshtriedcoding
@joshtriedcoding Жыл бұрын
Going to look into that next and how it compares to zustand / context / redux. Playing around with it will probably be fun
@rayramadita3018
@rayramadita3018 Жыл бұрын
@joshtriedcoding I have tried jotai, and it is so cool! Easy setup and powerful as global state management
@imkir4n
@imkir4n Жыл бұрын
I found it really hard to understand Redux before. Then, I discovered Zustand and tried it in a project; it's so cool and effective compared to Redux. It doesn't require a lot of setup, boilerplate, and other stuff. Once I understood the Zustand flow, I found Redux Toolkit much easier to use.
@chrisstucker1813
@chrisstucker1813 Жыл бұрын
Redux is like the PHP of state management. It’s ugly, disliked and isn’t the most elegant but it sure as hell gets the job done. Redux deserves more love lol
@rmcodes
@rmcodes Жыл бұрын
@@chrisstucker1813 Redux was an important step in the future like 8 years ago. Sure, its still in use but as we move forward much like jquery its usage will slowly dwindle. Hmm, side note jquery still has updates :).
@chrisstucker1813
@chrisstucker1813 Жыл бұрын
@@rmcodes redux toolkit is pretty nice and easy to use. Do you use Zustand?
@PrinzEugen39
@PrinzEugen39 Жыл бұрын
When i discovered redux i was simply amazed by the devtools
@saadsiddiqui9151
@saadsiddiqui9151 Жыл бұрын
Zustand is good, but after using Jotai, it has become a lot simpler to manage states in the app in a clean manner
@tonyabracadabra6935
@tonyabracadabra6935 Жыл бұрын
let's call jotai production ready recoil
@KangJangkrik
@KangJangkrik Жыл бұрын
Hol' up 1:15 how did you do that?
@dopetag
@dopetag Жыл бұрын
btw Zustand way is better for performance as it will not rerender all components involved ("Everything that consumes a context re-renders everytime that context’s state changes.")
@joshtriedcoding
@joshtriedcoding Жыл бұрын
I didn't know that actually, thanks for sharing man. Very interesting
@dopetag
@dopetag Жыл бұрын
@@joshtriedcoding you would still need to use shallow from zustand in some cases when you have arrays or objects in a state
@ts8960
@ts8960 Жыл бұрын
so state management is basically having globally accessible states/vars? all this time I thought it was some serious stuff like whatever redux is
@good-dev-student
@good-dev-student Жыл бұрын
❤ Thank you
@joshtriedcoding
@joshtriedcoding Жыл бұрын
Welcome champ
@naishe
@naishe Жыл бұрын
Jotai feels more fun and simple to me.
@good-dev-student
@good-dev-student Жыл бұрын
Any new video?
@SulagnoGhosh
@SulagnoGhosh 2 ай бұрын
OMG THANK YOU FOR SAVING ME
@carlosricardoziegler2650
@carlosricardoziegler2650 Жыл бұрын
I think JOTAI did “same” approach
@susanoo4081
@susanoo4081 Жыл бұрын
Jotai is better for simple cases, however for complex cases just use zustand
@kingjoo8309
@kingjoo8309 Жыл бұрын
Good job bro 👍❤
@smotch7533
@smotch7533 Жыл бұрын
hmm, wheres the reducer?
@DanielClipsTVS
@DanielClipsTVS Жыл бұрын
Wtf this is so good
@atemrandyasong5710
@atemrandyasong5710 Жыл бұрын
Redux is still champion 🏆
@mohsinejaz6882
@mohsinejaz6882 Жыл бұрын
legendState is king
@asimalqasmi7316
@asimalqasmi7316 Жыл бұрын
Waiting for this 🎉
@honestslave
@honestslave Жыл бұрын
Make A Video On How To Use React-hook-form With TinyMCE(Rich Text Editor) on Submit along with the Other input Fields. BEST OF LUCK 🎉
@freefakechannel7212
@freefakechannel7212 Жыл бұрын
But we can't use it with next js app dir 😑
@krtirtho
@krtirtho Жыл бұрын
isn't the pronunciation "jaa stand"
@firewatermoonsun
@firewatermoonsun Жыл бұрын
It looks better than Jotai.
@d13-s8b
@d13-s8b Жыл бұрын
I love jotai
@runaway09
@runaway09 Жыл бұрын
this is like pinia for vue
State Managers Are Making Your Code Worse In React
13:33
Web Dev Simplified
Рет қаралды 199 М.
Zustand - Complete Tutorial
19:27
Cosden Solutions
Рет қаралды 101 М.
PRANK😂 rate Mark’s kick 1-10 🤕
00:14
Diana Belitskay
Рет қаралды 11 МЛН
У вас там какие таланты ?😂
00:19
Карина Хафизова
Рет қаралды 27 МЛН
ТЫ В ДЕТСТВЕ КОГДА ВЫПАЛ ЗУБ😂#shorts
00:59
BATEK_OFFICIAL
Рет қаралды 3,7 МЛН
How Did I Not Know This TypeScript Trick Earlier??!
9:11
Josh tried coding
Рет қаралды 216 М.
Why Everyone Loves Zustand
29:27
Theo - t3․gg
Рет қаралды 104 М.
What Large-Scale Software Looks Like
18:32
Josh tried coding
Рет қаралды 28 М.
The Problem with React Server Actions
9:45
Josh tried coding
Рет қаралды 22 М.
Why I Moved from React Redux to Zustand and Why You Should Too!
19:24
Global State Management in NextJs 14 Using Zustand
51:17
Hamed Bahram
Рет қаралды 32 М.
React Query Is (Still) Essential - My Favorite React Library
11:04
Theo - t3․gg
Рет қаралды 156 М.
Mastering React Context: Do you NEED a state manager?
37:26
Jack Herrington
Рет қаралды 100 М.
PRANK😂 rate Mark’s kick 1-10 🤕
00:14
Diana Belitskay
Рет қаралды 11 МЛН