Comparison
How is Jotai different from Zustand?
Name
Jotai means "state" in Japanese. Zustand means "state" in German.
Analogy
Jotai is close to Recoil. Zustand is close to Redux.
Where state resides
Jotai state is within React component tree. Zustand state is in the store outside React.
How to structure state
Jotai state consists of atoms (i.e. bottom-up). Zustand state is one object (i.e. top-down).
Technical difference
The major difference is the state model. Zustand is basically a single store (you could create multiple stores, but they are separated.) Jotai is primitive atoms and composing them. In this sense, it's the matter of programming mental model.
Jotai can be seen as a replacement for useState+useContext. Instead of creating multiple contexts, atoms share one big context.
Zustand is an external store and the hook is to connect the external world to the React world.
When to use which
- If you need a replacement for useState+useContext, Jotai fits well.
- If you want to update state outside React, Zustand works better.
- If code splitting is important, Jotai should perform well.
- If you prefer Redux devtools, Zustand is good to go.
- If you want to make use of Suspense, Jotai is the one.
How is Jotai different from Recoil?
(Disclaimer: the author is not very familiar with Recoil, this can be biased and not accurate.)
Developer
- Jotai is developed with collective work by a few developers in Poimandres (formerly react-spring) org.
- Recoil is developed by a team at Facebook.
Basis
- Jotai is focusing on primitive APIs for lean learning, and it's unopinionated. (The same philosophy with Zustand)
- Recoil is full featured for big apps with various requirements.
Technical difference
- Jotai depends on atom object referential identities.
- Recoil depends on atom string keys.
When to use which
- If you want to learn something new, either should work.
- If you like Zustand, Jotai would also be pleasant.
- If your app heavily requires state serialization (storing state in storage, server, or URL), Recoil comes with good features.
- If you need React Context alternatives, Jotai comes with enough features.
- If you would try to create a new library, Jotai might give good primitives.
- Otherwise, both are pretty similar about the general goals and basic techniques, so please try both and give us a feedback.