State Management in React Will Never Be the Same

Поделиться
HTML-код
  • Опубликовано: 4 янв 2025

Комментарии • 114

  • @StCost
    @StCost Месяц назад +12

    Much better than props drilling, love it. That's what I expected React.Context to actually work like, nice

  • @KeganVanSickle
    @KeganVanSickle 22 дня назад

    This is awesome. It makes me want to remove my context providers. Great video, subscribed!

  • @viniciusalmeida741
    @viniciusalmeida741 Месяц назад +3

    Great video, great library! Thanks for the tip! This makes things really easier

  • @cloudagnostic
    @cloudagnostic Месяц назад +16

    Wow! I’ve always hated handling state in react. I always used prop drilling, but this makes me want to get back into coding again! Great video!!

    • @elmalleable
      @elmalleable Месяц назад

      props is react with hard labour

    • @AustinDavisTech
      @AustinDavisTech  Месяц назад +2

      That's great to hear! Prop drilling can definitely be a nightmare lol, it's so easy to lose track of things once your app gets the slightest bit complex

  • @furycorp
    @furycorp 27 дней назад

    Jotai is same creator/maintainer (dai-shi) as zustand which you mention. He has writeups that help explain which library to use depending on requirements.

  • @r0nni34
    @r0nni34 Месяц назад +7

    Nano store is awesome as well.. it's small reactive and works with react, solid ,native js or any famous framework.
    Great fit for. Small to medium size projects.
    If you use nano store with Astrojs the store you can be shared between frameworks.. you can make a change in solid component and react component will re-render if needed

    • @AustinDavisTech
      @AustinDavisTech  Месяц назад

      I'll have to check this out!

    • @shlokbhakta2893
      @shlokbhakta2893 28 дней назад

      I can vouch for nano stores, super cool and really small weighing in at 286 bytes 😂

  • @bwsstha8864
    @bwsstha8864 3 дня назад

    Thanks for enlighting me about this awesome library. It was a great video. I would want more indepth video about jotai with complex state like non-primitives and other feature provided by Jotai with real world example.
    Also if possible would you please share Jotai optimized version so that there is no un-necessary re-render like Jotai's focusAtom or selectAtom.

  • @IncomingLegend
    @IncomingLegend Месяц назад +5

    great video! I like that you get to the point! I tried to like zustand but it felt weird and cumbersome however jotai seems like a way better fit for me!

    • @AustinDavisTech
      @AustinDavisTech  Месяц назад

      For sure! Unless your project is super complex, I think simpler is generally better :)

  • @jaycodes8790
    @jaycodes8790 Месяц назад

    Thank you very much..... You explained very well 👍👍

  • @henriquematias1986
    @henriquematias1986 Месяц назад +2

    This is wicked, somehow very similar to zustand but yet seems even simpler indeed.
    Would be nice to see how types work on typescript and how more complex state works too, for instance if you have several variables and a few set/get functions like the usual zustand drill.

    • @tbkswagg
      @tbkswagg Месяц назад

      made by the same guys lol

  • @emilryden8306
    @emilryden8306 Месяц назад +3

    THIS CHANGES EVERYTHING! 🙃

  • @Norfeldt
    @Norfeldt Месяц назад

    I would argue that putting state in the url (via search params) is my perferred way. That means you can mount your components everywhere and they will be context aware by default.

  • @AbelShibabaw-ng1qp
    @AbelShibabaw-ng1qp Месяц назад +3

    what about zustand it feels like it works like jotai would but the setter and state is dynamic and we can add extra methods using zustand

    • @AustinDavisTech
      @AustinDavisTech  Месяц назад +1

      That's a great point! I haven't used Zustand a ton yet (still testing it out) but in my opinion Zustand would likely be a better choice if your app is highly complex. Not quite as cut and dry as Jotai, but it has the capability to do more. After all both Jotai and Zustand are made by the same person, for that exact reason

  • @anxpara
    @anxpara Месяц назад +3

    Why does react need n +1 state management libraries when svelte has built-in state management?

    • @AustinDavisTech
      @AustinDavisTech  Месяц назад +1

      That's a great question. React does technically have support for global state, using contexts. You can wrap your app (or subtree of the app) in a context provider, and then React components within that subtree can access the state. The problem is, if you state gets a bit more complicated or needs to not be so rigid, contexts are not always the best solution. You end up having to wrap your App with multiple, sometimes dozens (yes I've actually seen this) of context providers, and it can get really messy and hard to track. The reason for libraries like Jotai, Zustand, Redux, etc, popping up is to try and offer a better and more flexible way to manage global state.
      It's a bit unfortunate that so many libraries exist because it complicates things. It's also worth mentioning that React is a library while Svelte is a framework. React is great at doing what React does, but it stays pretty unopinionated about things like global state management and routing, whereas vanilla Svelte is a bit wider than vanilla React. I think both cases are good in their own way, part of what makes React good is that since it stays unopinionated, it meshes well with almost any library and is super flexible!

    • @anxpara
      @anxpara Месяц назад +1

      ​@@AustinDavisTech "part of what makes React good is that since it stays unopinionated, it meshes well with almost any library"
      is that really true though? with svelte, I can use vanilla js libraries directly without having to write wrappers. and svelte isn't built on a vdom, so i can access the dom directly

    • @dualShockRK98
      @dualShockRK98 Месяц назад

      @@anxpara Whether it is true or not, it depends on the person. I personally like having multiple choices on what technology stack I want to use for development. For example in many frameworks everything you need to develop an app is pretty much included. In React you might have to decide between Tanstack Query vs RTK Query vs SWR, for remote state, and what it is good for is that imo it pushes the industry forward with people always trying an improving on certain libraries. Like when context and redux were pretty much the only tools used for state management, pretty much everyone agreed that to manage state in react was a pain in the ass, specially classic redux. Now you have many options to choose from. Its true its hard to keep up with all of them, but I personally just find it better than just using a framework. But I feel like it is personal preference at the end of the day. Many people like full fledged frameworks a lot more. Pros and Cons to both

  • @TacticalCheetaGaming-w2k
    @TacticalCheetaGaming-w2k Месяц назад +18

    zustand and zotai developed by the same person so both have place

    • @viktor_zhurbin
      @viktor_zhurbin Месяц назад +4

      Poimandres is a dev collective, not a person

    • @AustinDavisTech
      @AustinDavisTech  Месяц назад +5

      Big agree! They both provide a ton of value, and you could actually use them together if you wanted to. In Jotai's docs there's a guide on how to hook it up with Zustand

    • @rand0mtv660
      @rand0mtv660 Месяц назад

      @@viktor_zhurbin but these libraries were created by a single person and he is called Daishi Kato. He even created a third library called Valtio. So Zustand, Jotai and Valtio were all created by the same person. All are state management libraries, but built on different principles.

    • @philheathslegalteam
      @philheathslegalteam Месяц назад +2

      @@viktor_zhurbin Daishi Koto made both...

    • @furycorp
      @furycorp 27 дней назад

      @@viktor_zhurbin yes its a collection of maintainers but look at the commit history it was still created by dai-shi and is still maintained by him. have you considered that this developer could also be a member of this collective?

  • @wonjaehwang7670
    @wonjaehwang7670 Месяц назад

    So if you want to use the global state you need to always import the original atom() to the component

  • @bariqdharmawan6604
    @bariqdharmawan6604 Месяц назад

    Can you show us your code? I wanna learn it more detail especially the code inside component

  • @peterxavier1
    @peterxavier1 Месяц назад +2

    Jotai seems really easy to use, with absolutely no boilerplate. But i do not think it will scale well in more complex applications. Zustand will be a better fit in that case.
    Great video BTW

    • @darthvader4899
      @darthvader4899 Месяц назад +3

      why? why would zustand scale not jotai?

    • @peterxavier1
      @peterxavier1 Месяц назад +2

      @@darthvader4899 My previous comment was based solely on what was shown in the video (this was my first time seeing the library). So, thinking of integrating it with some complex apps I've worked with, scalability seemed problematic.
      But going through its docs, my opinion of Jotai has changed. I believe its atom-based architecture allows for an application to be highly modular, consequently improving its scalability.

    • @BoonBoonitube
      @BoonBoonitube Месяц назад +1

      I agree, a while back I cross shopped jotai v zustand v redux toolkit and of the 3 zustand seemed to be the most flexible. Zustand can be nearly as atomic as jotai, but then built out to be as complex as redux. Zustand has the concept of a store, which helps organize global state into an obvious spot. I was concerned with jotai not having an organizing principle.
      For truly app wide global state, we use react context. That handles things such as app theme, app authority etc. Other than that, we don't have a need for truly app wide global state. We use zustand for global module/feature level state. Zustand allows module state to be as simple, or complex as that feature requires.

    • @AustinDavisTech
      @AustinDavisTech  Месяц назад +1

      I get your point, and I think a lot of people would probably agree with you about Zustand. However I do think you may be underestimating Jotai a bit, as I have seen it scale very well so long as it's handled responsibly. Two solutions that are created by the same person and great in their own ways!

    • @nizomsidiq3
      @nizomsidiq3 Месяц назад

      @@BoonBoonitube Im not really sure but imho better to use zustand for app wide state because of not requiring context provider, thus it will only trigger re-render on component that use that specific state.
      afaik the cons of using context is that triggers rerender to the providers children

  • @botyironcastle
    @botyironcastle Месяц назад +1

    jotai is the best

  • @pexeixv
    @pexeixv Месяц назад +2

    So it's just global state? Does it have anything similar to Thunk in Redux? Even if it does not, I can see where Jotai will be useful.

    • @AustinDavisTech
      @AustinDavisTech  Месяц назад

      It's global state by default unless you scope it then it only exists within its own scope (similar to how regular variables are scoped). Vanilla Jotai doesn't have thunk functionality like Redux, but that's also part of the beauty as to how simple it is

  • @philheathslegalteam
    @philheathslegalteam Месяц назад +2

    React devs have forgotten the best state management library of them all, the U R L.
    I love this library, however I only use it in cases where I don't want to expose state to the user like setting a navbar's sticky state. Everything else goes into the URL bar in our projects.

    • @AustinDavisTech
      @AustinDavisTech  Месяц назад

      I do think storing state in the URL is something people completely forget about and don't utilize as much as they could. However, some might say that even with a routing library, the URL still exists outside of the React ecosystem/lifecycle since it's part of the browser, making it less pure React, as opposed to something like Jotai that is 100% tied to the React DOM. This definitely can have upsides though depending how you look at it. Ultimately I think it is best to choose what works best for you :)

  • @real23lions
    @real23lions Месяц назад

    It’s simple but it could get difficult to handle if you have many levers

  • @shaddyrogue9430
    @shaddyrogue9430 Месяц назад

    That’s great. Simple explanation. But it doesn’t have any vulnerable issue right that’s my only concern.

  • @ChArham-bs1ne
    @ChArham-bs1ne Месяц назад

    Jotai seems very easy to use, with not much of a setup. But having a bunch of global states worries me for the performance. Personally, I like useImmer and useImmerReducer. I don't mind setting up the reducer function once, and Immer helps with the immutability problem that native reducer had.

  • @gdebojyoti
    @gdebojyoti Месяц назад +9

    This really looks fantastic! But...
    1. Maintenance may end up becoming a nightmare in large scale production apps - especially in companies where PR reviews are not done "properly". 😉
    2. I am curious what the performance is like in medium and large scale apps. 🤔
    Thank you making this video though. Best thing I learnt today!

    • @ahmedelbarqy4849
      @ahmedelbarqy4849 Месяц назад +1

      I've been actually working with jotai for quite sometime now, and yeah number 1 is a really valid point
      i didn't benchmark it with other state management solutions but it seems like it's working fine

    • @AustinDavisTech
      @AustinDavisTech  Месяц назад +1

      That's a great point! Because it's so simple it certainly could be easy to abuse on apps that are super large or complex. My company uses Jotai however and we've never had an issue with it to my knowledge. But to your point, I think something like Zustand is a valid use case when this concern pops up! In terms of performance I have not officially benchmarked it or seen official benchmarks versus other solutions/libraries, however I can say in my experience with both medium scale apps (my personal projects) and large scale apps (my companies codebase) it's been just as fast as normal React state or contexts!

    • @grzesieksgs
      @grzesieksgs Месяц назад

      Ive sucessfuly migrated to jotai, an app which has big amount of data (air traffic over US) which is updated with few seconds interval.
      With jotai, its generalny easier to avoid rerenders, than eg. using redux. In terms of jotai performance overhead - its marginal, I recommend having a look at their codebase.
      The not so great part is that you need to get used to different data model, and atoms itself have some uncomfortable (for me) quirks.
      Theres some complexity while dealing with promises, or synchronizing state from outside source. 😊

    • @gdebojyoti
      @gdebojyoti Месяц назад

      @@AustinDavisTech I'll try to find a way to measure the performance of these state management solutions. Not sure how to begin, but I'm sure I'll enjoy the process of learning new things. 🙂

    • @gdebojyoti
      @gdebojyoti Месяц назад

      Btw, even though I have been working on React projects for many years now, I feel like I know very little. Videos such as this one will definitely be the push that I need to get good. 😛

  • @shivambajpai5519
    @shivambajpai5519 Месяц назад +2

    Is it like recoil lite?

    • @AustinDavisTech
      @AustinDavisTech  Месяц назад

      From my understanding it's pretty similar to recoil, although I'm not extremely familiar with that library so it's hard for me to say for certain

    • @artemtarasenko9744
      @artemtarasenko9744 Месяц назад

      From my understanding Jotai was done looking at Recoil. But Recoil was a little more complex. Still, such a shame Fb stopped Recoil development.

    • @D1g1talAli3n
      @D1g1talAli3n Месяц назад

      isn’t this just recoiljs? Also Solid has this built in

  • @advancedprogramming62
    @advancedprogramming62 Месяц назад +1

    it's same principal as signals

  • @JacobSean-iy3tl
    @JacobSean-iy3tl Месяц назад +1

    Nice , very niceee

  • @codewithshriekdj
    @codewithshriekdj Месяц назад

    i used it but it's too slow. it updates atom very slowly, i can't use more than 4 atoms after that it become very slow.

    • @AustinDavisTech
      @AustinDavisTech  Месяц назад

      It's always been incredibly fast for me! It should be comparable in speed to useState/React contexts so long as you're not initializing atoms INSIDE React components and not causing unnecessary state changes & re-renders

  • @SonAyoD
    @SonAyoD Месяц назад +3

    Zustand is just a this with more bells and whistles.

    • @AustinDavisTech
      @AustinDavisTech  Месяц назад

      Zustand seems really powerful, and I'll probably be making a video here on it soon once I get more experience with it. But if you want an extremely simple, out-of-the-box solution then Jotai is your guy :)

  • @noopurp123
    @noopurp123 Месяц назад

    I think preact signals makes it much more simpler than this. This is a nice state management library tough...

  • @magaramol9175
    @magaramol9175 Месяц назад +3

    Nice , but what about performance 😊

    • @AustinDavisTech
      @AustinDavisTech  Месяц назад +1

      I don't know the official benchmarks of Jotai, but I will say my company uses it pretty extensively on a large application, and performance has never been an issue. Expect it to run at the same speed as normal React state + contexts

  • @mustafabektas7207
    @mustafabektas7207 Месяц назад

    God this is beautiful.

  • @BryanDevsCoding
    @BryanDevsCoding 28 дней назад

    nice

  • @profesor08
    @profesor08 Месяц назад

    State managers based on atoms are good only on examples or when they are simple. But having many atoms, on medium or large projects, can make the state management code realy messy. Especially when you read code after a few months xD

  • @dugtrioramen
    @dugtrioramen Месяц назад +1

    Valtio is even crazier. It's also another poinandres react state manager

    • @AustinDavisTech
      @AustinDavisTech  Месяц назад

      I'll have to try that out!

    • @dmz985
      @dmz985 Месяц назад

      an problem with Valtio is it's not very suited to store complex objects (e.g a MediaStream) because it uses Proxies, whereas Zustand and Nanostores doesn't have issues with them

  • @bopon4090
    @bopon4090 Месяц назад +1

    Its something like signal

  • @tr3m0r1ty
    @tr3m0r1ty Месяц назад +1

    Wow. Like a zustand

  • @georgezummar6071
    @georgezummar6071 24 дня назад

    contextApi killer?

  • @Kimo.Codess
    @Kimo.Codess Месяц назад +1

    This has saved me from so much pain 😹

  • @theprantadutta
    @theprantadutta Месяц назад

    Recoil actually does exactly this, how is this better than Recoil, Recoil actually has more features like getters, setters, family, effects etc.

  • @realm087
    @realm087 Месяц назад

    Isn't this just signals with extra steps?

    • @AustinDavisTech
      @AustinDavisTech  Месяц назад +1

      not really, Jotai and signals are very similar in a lot of ways, but ultimately behave differently behind the scenes

  • @mouradaouinat8721
    @mouradaouinat8721 Месяц назад +1

    you 360 no scoped this tut

  • @muratcemyalin
    @muratcemyalin Месяц назад

    it is just using createcontext behind the scenes.

    • @tusharsnx
      @tusharsnx Месяц назад +1

      It can out be. It doesn't require you to wrap your app within a Provider.

    • @realderek
      @realderek Месяц назад

      @@tusharsnx Unfortunately, jotai-scope is using a context within the implementation of ScopeProvider.

    • @tusharsnx
      @tusharsnx Месяц назад

      @@realderek You're correct. To create a scoped atom you need context provider.

  • @yasirlambawala2256
    @yasirlambawala2256 Месяц назад +1

    This is same as recoil

  • @Punch-gf6ob
    @Punch-gf6ob Месяц назад

    Jotai is bigger than Zustand

  • @Nellak2011
    @Nellak2011 Месяц назад +3

    Congrats.
    You now made your app infinitely harder to test and debug.
    Global State is a problem. In fact, it was such a big problem a whole programming paradigm was created to address it.

    • @ChArham-bs1ne
      @ChArham-bs1ne Месяц назад

      Exactly, that's what my biggest concern was

    • @AustinDavisTech
      @AustinDavisTech  Месяц назад +1

      I strongly disagree. Jotai is not a replacement for using normal React state. As long as you're not spamming atoms everywhere and you're using global state responsibly, it is 100% a better alternative than dodging global state entirely and prop drilling to infinity and beyond. There's a reason React itself supports global state with contexts and so many global state libraries have popped up. Web dev can get really complex, and without some sort of state management like Jotai, Zustand, or even contexts it becomes an absolute nightmare to navigate

    • @Nellak2011
      @Nellak2011 Месяц назад

      @AustinDavisTech Contexts are semantically identical to Jotai.
      The fundamental problem here is that it is unregulated and not isolated.
      If a component changes state somewhere you can't know what it is without traceability like Redux offers with reducers.
      Moreover, since you have global state you have to recreate the entire DOM to test one compoment.
      No matter how you spin this, it is unregulated Global state which is an Anti-Pattern.
      I realize wish Front End influencers would study software Engineering Principles instead of hyping up Anti-Patterns.

    • @AustinDavisTech
      @AustinDavisTech  Месяц назад +1

      Okay now you're just making stuff up 😂. Just because atoms effectively function as a global useState with context does not mean the entire app is a dependency of every single atom and the entire DOM re-renders for every single atom. If you make for instance ten layers of nested components and use an atom for layers 3 and 7, rather than prop drilling, the entire app (layers 0-10) does not all re-render. This claim is objectively false. Components only become dependencies of an atom if they subscribe to it, exactly how contexts work. Please go and test for yourself and you'll see exactly what I mean. I'm not sure where you got this information from?
      The only correct statement in here is that it is not isolated, which is the whole point. Complete isolation in a React app is not possible if you're building anything harder than a to-do list. Even if you're prop drilling, you're still making components become dependent on one another. Jotai, along with many other state management libraries, simply offers a better way to do it.
      Again, there's a reason why these libraries exist and React itself has built-in support for state sharing. Frontend developers aren't dumb or bad for doing this, in fact the most functional React apps are almost ALL going to have some sort of state management system in place. Just like literally everything else in programming, global state can be bad if it's abused. Memory management in C can be abused, but it'd be ridiculous for me to claim that nobody should touch memory in C because it's dangerous. I understand where you're coming from but some of your claims are objectively false, and applying a blanket statement like "global = bad" doesn't address the genuine need for state management systems in React apps.

    • @Nellak2011
      @Nellak2011 Месяц назад

      @AustinDavisTech Look the problem is simple. Let me simplify so you can understand.
      1. It is unregulated global state
      2. It is not isolated
      So no matter what argument you have, it fails this fundamental test.
      Why is it unregulated?
      -> No one knows what updated what
      Why is unregulation bad?
      -> Because you cant debug it easily
      Why is it not isolated?
      -> Because it introduces non local coupling. Your components are not a function if the props but of some hidden state elsewhere.
      Why is lack of isolation bad?
      -> It makes things harder to test and harder to reason about. Instead of being able to think about it in isolation, you have to consider the whole app.
      How do you do isolation and global state management?
      -> You explicitly pass your dependencies as props in 1 direction. Never do 2 way prop-drilling. For example, you have your state in your store, you pass the selectors used by the component explicitly down.
      But we can directly access the store with a hook, it is more complicated to pass down props explicitly. Why do you advocate that?
      -> Sure, we can shoot ourselves in the foot if we want, but it doesnt mean it is good to do so. The reason we pass the selected state from the store explicitly is so we can achieve isolation and so we become agnostic to the state provider. If we access it directly, we make a coupling to that specific store. In other words we make an implicit dependency and so to test the component we need to now mock the whole redux store instead of just passing in props. It is literally the bananna and jungle problem.
      ==> Therefore we should avoid unregulated global state like in context api or jotai. It leads to well known anti-patterns and is anti-thetical to good software engineering practices.

  • @MohamedAzizKhayati
    @MohamedAzizKhayati Месяц назад

    Preact signals is much better and less bloated.

    • @AustinDavisTech
      @AustinDavisTech  Месяц назад

      Not knocking signals at all but this is a gross oversimplification. Jotai is not bloated in the slightest AND is more "react-y" than signals are. Signals are cool and may have their place, but this kind of comparison doesn't do it justice

  • @Nellak2011
    @Nellak2011 Месяц назад

    Austin Davis deletes comments he doesn't like just so you all know.

  • @luberius
    @luberius Месяц назад

    nah, valtio is better. no boilerplate like this

  • @antondoit
    @antondoit 10 часов назад

    nice