r/reactjs • u/deadcoder0904 • Aug 02 '22
Discussion Zustand vs Jotai vs Valtio? Which state management library do you prefer created by the same team?
Please don't mention other state management libraries.
I want to see which state management library most people use created by the same team?
77
Upvotes
65
u/[deleted] Aug 02 '22 edited Aug 05 '22
Recently I made a research on this subject for my best React libs post. According to my findings, those 3 libs use 3 different architectural patterns. And projects with different purposes and sizes might use one of them according to their needs. So maybe it is better to ask which one you prefer for what kind/size of projects, as there isn't a single best option suitable for all projects.
My findings roughly are:
Zustand uses flux pattern and is suitable for mostly large scale apps. It is an alternative for Redux.
Jotai uses atomic pattern and is suitable for mostly middle-large scale apps. It is an alternative for Recoil or useContext/useState.
Valtio uses proxy pattern, is mutable, and mostly suitable for small scale apps. It is an alternative for Mobx.
18
u/vincaslt Aug 03 '22 edited Aug 03 '22
They are all great, they all can solve the same problem, and they are all different.
Zustand - offers a top-down approach to the global state. Meaning that you start modeling your stores from the overview, down to the details. For example, if you were building a store for a blog, you'd model your store somehow like this
blog->posts->post->id,title,content,authorwhich is very natural and intuitive for most people and works for most apps.Jotai - is a mindset shift from Zustand, because of its bottom-up style. You first define the granular pieces of state (atoms) and then build them up into bigger pieces of state by combining them in selectors (they're just functional atoms in Jotai I think). The selector has a different meaning in top-down and bottom-up approach:
These are obviously not set in stone, as it mostly depends on how you model your state, but that's the general idea how I understand it.
Valtio - mostly optimizes for state writing by allowing you to directly mutate the global state. To me it's similar to Zustand, except that state updates are made simpler.
Conclusion
From what I've experienced, top-down (Zustand, Redux, Mobx) is a bit better for modeling the app domain, as it gives you a better overall picture of the state structure. Bottom-up (Jotai, Recoil, hookState) is a bit better for performance-driven apps that have many moving parts that require a large amount of read-write operations to small pieces of state. This would normally be modeled as a nested global state in top-down state management libraries.
As for which one I like best, I would choose them based on what kind of app I'm building.
I would probably skip Valtio though, as I don't see much benefit of it over the others.(Read my expanded thoughts on Valtio in the comments below)35
u/[deleted] Aug 02 '22 edited Aug 02 '22
theo explained it very well: https://youtu.be/fa6-Mn0Eybg?t=13396
jotai for atomic, dispersed state bits, similar to useState but render optimised and with a few extras (state derivatives). works well in teams.
zustand for centralised javascript stores. if you have a state schema, or your state is json, this will make sense. works well in teams.
valtio is fantastic for smaller projects that have no problem with mutation and updating state from multiple place. works best in everything you do personally.
in a team project i'd prefer zustand if our state is json. i use jotai for other professional stuff, also in teams but where the state model is more free floating. i use valtio for everything else, every personal small scale project.
3
u/danzo0x1 Nov 01 '22
We've decided to move from redux and I had to choose between those. I read this issue written by the guy behind those three libraries and I have choosen zustand. until now everything is going so smooth.
2
u/jimmysay24 Aug 03 '22 edited Aug 03 '22
For me ... depends on which one is better for you, although honestly, they all need improvement. And a lot. Redux is a headache for a tooth. We've all had a toxic relationship with her. Hahaha. But i prefer zustand or jotai. There are differences between them. Valtio is not bad either.
156
u/Turbulent-Line3591 Aug 02 '22
useState and prop drilling 100 components
61
u/ernesto__bungforto Aug 02 '22
I prefer Zustand. Tiny, straightforward, scalable.
21
u/TwiliZant Aug 02 '22
I use Zustand and Jotai. I would also use both in the same application since they are based on different state management models.
I don't use Valtio because I try to avoid proxy-based reactivity in React.
In reality I use state management very sparingly. Most of my data lives in React Query and I rather would change my component structure than to make state globally available.
Daishi Kato, the maintainer of these libraries, wrote a book called "Micro State Management with React Hooks" that explains the different state management approaches these libraries take.
10
u/punio4 Aug 02 '22
Zustand and immer work great together. Like a very lightweight RTK.
But I prefer Valtio
7
u/nazzanuk Aug 02 '22
Jotai, I just love keeping the state in small individual atoms. Grouping by big domain objects just adds mental work deciding under which domain everything sits, Jotai just works so well at scale.
7
u/[deleted] Aug 02 '22
Jotai for sure.
I think the atomic pattern can accomplish everything zustand can, but more, and with less boilerplate.
5
u/Any-Plant-4935 Mar 11 '23
Valtio can do anything Zustand can and more...
Why most people opt in for Zustand, is because it's easier to apply a Redux-like paradigm to a simpler version of state + actions on state. This works well if your state model is defined very formally.
But if you have a different use-case, for state with a JSON like structure that branches off into infinity and you don't know the shape of your object, then Valtio is more suited as the proxy model triggers subscribers on any node of the tree.
For UIs that manipulate larger trees then and you want to only rerender at those nodes, Valtio is perfect
1
u/saito200 Aug 02 '22
Make a reddit poll
1
u/Zoqqer Aug 02 '22
Why limit yourself to just those?
1
u/RevolutionaryAd1557 Aug 02 '22
just thought I commented so I can keep up to date with this thread.
3
u/ctjhoa Aug 02 '22
https://frontendmastery.com/posts/the-new-wave-of-react-state-management/
This blog post highlights some differences
15
u/treetimes Aug 02 '22
I’ve never heard of any of these
2
u/totalolage Aug 02 '22
I have not tried Valtio, I do use Zustand in production applications. I tried out Jotai and it seems to be geared at a completely different type of state management than Zustand.
Currently I use Zustand with immer for "big" stores with deep objects and complicated operations. I will probably end up using Jotai for several "small" states, like passing a
Filethat is uploaded on one page and then used on another.If anyone could enlighten me as to Voltio's role, I'm very interested.
9
u/[deleted] Aug 02 '22
What are all these words. Are these used in professional environments or more hobbyist?
5
u/lordaghilan Aug 02 '22
I still like Redux tbh. The "boilerplate" takes like 5-10 mins.
2
u/italoand Aug 02 '22
They were created not only by the same team but actually by the same person. His Twitter is very informative about those 3 libs: https://twitter.com/dai_shi
As for the my answer:
Valtio. I can't think of any reason for using any other state management library if you understand how JavaScript Proxy works, and Valtio was the best implementation we had yet. The only reason to not use it is if you or your team lack the maturity to use something of this nature (the tradeoff is that it is really hard to keep track of mutations if you don't create separate methods for mutating the state instead of mutating it directly, losing the actual purpose of the library).
Someone here mentioned it as only suitable for small scale apps and compared it to MobX.
I'm using and advocating it on big scale apps and we never had any problems. As for comparing it to MobX, Valtio doesn't have 10% of the complexity MobX has, so I think it's unfair to compare them since they have different "approaches" to Proxy.
I'm currently using Valtio with Next.js (with SSR support) on new projects.
My personal state management tier list
1
u/x7dl8p Oct 16 '25
jotai
1
u/[deleted] Aug 02 '22
I’ve never used any of them. However, I think this submission itself is peak React!
1
u/[deleted] Aug 02 '22
Jotai state is within React component tree. Zustand state is in the store outside React.
1
u/sleepy_roger Aug 02 '22
Mobx.
1
u/RyanNerd Aug 03 '22
ReactN one team member but it's a hooked based liteweight state management library with Redux like interfaces but without all the boilerplate.
1
u/[deleted] Aug 02 '22
[removed] — view removed comment
1
u/[deleted] Aug 02 '22
[removed] — view removed comment