-
-
Notifications
You must be signed in to change notification settings - Fork 697
Description
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.
If you need a global store to bridge between two react renderers, zustand will only work.(no longer valid with jotai's provider-less mode, but zustand may work better.)