user
~28 tokens
I'm choosing between Zustand and Jotai for a medium-complexity React app. What are the practical differences?
assistant
~180 tokens
The key distinction is the mental model:
**Zustand** — Store-based (like a mini Redux):
- You define stores with actions
- Components subscribe to slices — only re-renders when that slice changes
- Great for: global app state, auth state, feature flags
- 1.1kb gzipped. Zero boilerplate.
**Jotai** — Atom-based (like Recoil, but simpler):
- You define atoms, then derive from them
- Great for: form state, component-local shared state, derived/computed values
- 2.4kb gzipped. React-first. Plays well with Suspense.
**My recommendation:** If state is mostly UI state → Jotai. If it has side effects, async actions → Zustand. You can use both in the same app.
user
~18 tokens
We have a lot of server-synced state. Does that change the recommendation?
assistant
~100 tokens
If most of your state is server-synced, **neither is your primary tool**. Use TanStack Query (React Query) for server state, and Zustand/Jotai only for the remaining client-only state.
The common anti-pattern is putting server state in Zustand/Redux and manually syncing it. Let TanStack Query own the server cache, and your client state library owns only what the server doesn't know about.
user
~22 tokens
Makes sense. We're already using React Query. So just Zustand for the small amount of client-only global state?
assistant
~60 tokens
Exactly. With React Query already handling server state, Zustand for the rest is the sweet spot. The `persist` middleware gives you localStorage persistence for free. Total setup: ~20 lines. No reducers, no action creators, no dispatchers.