Jotai
Minimal React state management with atoms as primitive building blocks for flexibility.
3. Used by agents' projects
Dependency in 35 public GitHub projects set up for AI coding agents that we scanned (0.6%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
From the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error
What Jotai does
Jotai builds React state from small atoms that compose into derived, writable or async atoms, and the site says renders "are automatically optimized based on atom dependency."
Jotai popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How Jotai is used
- Jotai is a dependency in 35 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (0.7% of the 4,867 JavaScript/TypeScript ones), #10 of 53 in state and data fetching.
- Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 195; those are left out of every share on this page.
- The most used alternative in our scan is Zustand (366 projects).
- Projects that use it most often also use Radix UI (77.1%), date-fns (74.3%), React (97.1%).
By coding agent
Often used with
Jotai in practice
Strengths
The site says the atom model "solves the extra re-render issue of React context" and "eliminates the need for memoization". It also claims a developer experience similar to signals while staying declarative.
The README lists a "Minimal core API (2kb)" and "No string keys (compared to Recoil)". Both are the maintainers' own claims.
Derived state uses the same <code>atom()</code> call. A read function as the first argument makes a read-only atom, and a write function as the second argument makes it writable. Leave out the read function and you get a write-only atom.
Read functions can be async, so an atom can fetch from a URL held in another atom. Write functions can be async too: you call <code>set</code> once the data arrives.
Watch out for
The README marks derived async atoms with a "needs suspense" badge that links to React's Suspense docs.
For server-side rendering with a framework such as Next.js or Waku, the docs say to add a Jotai <code>Provider</code> at the root of the app.
In the Next.js app directory, the provider goes in its own <code>'use client'</code> component. That component is then imported into the server-side root layout.
Primitive, derived and write-only atoms
import { atom } from 'jotai'
const countAtom = atom(0)
const countryAtom = atom('Japan')
const citiesAtom = atom(['Tokyo', 'Kyoto', 'Osaka'])
import { useAtom } from 'jotai'
const doubledCountAtom = atom((get) => get(countAtom) * 2)
function DoubleCounter() {
const [doubledCount] = useAtom(doubledCountAtom)
return <h2>{doubledCount}</h2>
}
const multiplyCountAtom = atom(null, (get, set, by) =>
set(countAtom, get(countAtom) * by),
)
function Controls() {
const [, multiply] = useAtom(multiplyCountAtom)
return <button onClick={() => multiply(3)}>triple</button>
}More about Jotai
Funding
- GitHub Sponsors: https://github.com/dai-shi
- Open Collective: https://opencollective.com/jotai
- Own page: https://daishi.gumroad.com/l/learn-jotai
- 21 GitHub sponsors
Packages around it
- @tanstack/react-query: Server-state fetching and caching
- tailwindcss: Utility-first CSS
- react: UI library Jotai is built for
- @radix-ui: Unstyled accessible UI primitives
- next: React framework
- class-variance-authority: Component variant class helper
More in State and data fetching
Alternatives
Jotai This page
Lightweight state management for React with minimal boilerplate.
Official Redux library with built-in best practices and reduced boilerplate for state management.
Get started
Install it.
npm install jotaiRules for your agent
## Jotai
- Define state as atoms with `atom(initialValue)`. Compute dependent values with derived atoms such as `atom((get) => ...)`.
- When a component only reads an atom, use `useAtomValue`. When it only writes, use `useSetAtom`. Use `useAtom` when the same component does both.
- For actions, use a write-only atom (`atom(null, (get, set, arg) => ...)`). For async actions, make the write function async and call `set` when the data is ready.
- The README marks derived async atoms as needing React Suspense, so plan for a Suspense boundary when you use them.
- With SSR in Next.js or Waku, add a Jotai `Provider` at the root. In the Next.js app directory, put it in a separate `'use client'` component and import it into the root layout.js server component.
- For persisting an atom in localStorage, `jotai/utils` provides `atomWithStorage(key, initialValue)`.
- v3.0.1 fixes a `useAtomValue` regression introduced in v3.0.0, and the release note says "Please update."