title | nav |
---|---|
Comparison |
1.04 |
Jotai means "state" in Japanese. Zustand means "state" in German.
Jotai is like Recoil. Zustand is like Redux.
Jotai state is within React component tree. Zustand state is in the store outside React.
Jotai state consists of atoms (i.e. bottom-up). Zustand state is one object (i.e. top-down).
The major difference is the state model. Zustand is a single store (although you could create multiple separate stores), while Jotai consists of primitive atoms and allows composing them together. In this sense, it's the matter of programming mental model.
Jotai can be 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.
- 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.
(Disclaimer: the author is not very familiar with Recoil, this may be biased and inaccurate.)
- Jotai is developed with collective work by a few developers in Poimandres (formerly react-spring) org.
- Recoil is developed by a team at Facebook.
- Jotai is focusing on primitive APIs for easy learning, and it's unopinionated. (The same philosophy with Zustand)
- Recoil is full featured for big apps with complex requirements.
- Jotai depends on atom object referential identities.
- Recoil depends on atom string keys.
- 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 share your feedback with us.