Jotai — Primitive and Flexible State Management for React
Jotai is an atomic state library for React. You compose atoms like React useState, and Jotai handles subscription, derivation, and async loading — all without the boilerplate of Redux or the global store of Zustand.
What it is
Jotai is an atomic state management library for React. Instead of a single global store, you define independent atoms that hold pieces of state. Components subscribe to only the atoms they use, so re-renders are minimal. Derived atoms compute values from other atoms, and async atoms handle data fetching -- all with an API as simple as useState.
Jotai targets React developers who find Redux too heavy and Context too limited. It suits applications where fine-grained reactivity and composable state pieces matter more than a centralized store.
How it saves time or tokens
Redux requires slices, reducers, actions, selectors, and middleware for even simple state. Zustand simplifies this but still uses a single store. Jotai eliminates all boilerplate: define an atom, use it in a component with useAtom. Derived state is a function, not a selector library. The mental model is useState that works across components.
How to use
- Install Jotai:
npm install jotai. - Define atoms:
const countAtom = atom(0)and derived atoms:const doubledAtom = atom((get) => get(countAtom) * 2). - Use in components:
const [count, setCount] = useAtom(countAtom).
Example
import { atom, useAtom } from 'jotai';
const countAtom = atom(0);
const doubledAtom = atom((get) => get(countAtom) * 2);
function Counter() {
const [count, setCount] = useAtom(countAtom);
const [doubled] = useAtom(doubledAtom);
return (
<div>
<button onClick={() => setCount(c => c + 1)}>
Count: {count}, Doubled: {doubled}
</button>
</div>
);
}
Related on TokRepo
- Coding Tools -- Frontend state management libraries
- Automation Tools -- Developer workflow tools
Common pitfalls
- Creating atoms inside component render functions. Atoms should be defined at module scope or memoized. Creating them during render causes infinite re-renders.
- Not using
Providerwhen you need isolated state trees (e.g., in tests or micro-frontends). Without a Provider, all components share the default store. - Overusing derived atoms for simple transformations that could be done inline. Atoms add subscription overhead, so only extract derived atoms when multiple components need the same computation.
Frequently Asked Questions
Zustand uses a single store with selectors for fine-grained subscriptions. Jotai uses independent atoms with no central store. Zustand is better for teams that prefer a single source of truth with clear boundaries. Jotai is better when state is naturally decentralized and composed from many small pieces.
Yes. Define an async atom with `atom(async (get) => { ... })` and Jotai handles loading states through React Suspense. When the async atom resolves, subscribed components re-render with the fetched data.
Yes. Use `atomWithStorage` from the `jotai/utils` package. It syncs atom values to localStorage, sessionStorage, or a custom storage backend automatically. State persists across page reloads and browser tabs.
Jotai atoms use React hooks and run in Client Components. For Server Components, pass server-fetched data as props into Client Components that use Jotai for interactive state management.
Jotai's core is under 3KB gzipped. It has no dependencies beyond React. The small size makes it suitable for performance-sensitive applications where bundle size matters.
Citations (3)
- Jotai GitHub— Jotai provides atomic state management for React
- Jotai Documentation— Core bundle under 3KB gzipped with no external dependencies
- Jotai Utils Docs— atomWithStorage for persistent state across page reloads
Related on TokRepo
Discussion
Related Assets
NAPI-RS — Build Node.js Native Addons in Rust
Write high-performance Node.js native modules in Rust with automatic TypeScript type generation and cross-platform prebuilt binaries.
Mamba — Fast Cross-Platform Package Manager
A drop-in conda replacement written in C++ that resolves environments in seconds instead of minutes.
Plasmo — The Browser Extension Framework
Build, test, and publish browser extensions for Chrome, Firefox, and Edge using React or Vue with hot-reload and automatic manifest generation.