Skip to content

Latest commit

 

History

History
72 lines (46 loc) · 2.4 KB

comparison.mdx

File metadata and controls

72 lines (46 loc) · 2.4 KB
title nav
Comparison
1.04

How is Jotai different from Zustand?

Name

Jotai means "state" in Japanese. Zustand means "state" in German.

Analogy

Jotai is like Recoil. Zustand is like 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 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.

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 may be biased and inaccurate.)

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 easy learning, and it's unopinionated. (The same philosophy with Zustand)
  • Recoil is full featured for big apps with complex 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 share your feedback with us.