API Reference

Jotai

Primitive and flexible atomic state management for React where state is composed from atoms.

Official Documentation ↗
CompatibilityThis documentation covers version v3.0.1. Check the official docs for the latest API surface.

Installation

npmnpm install jotai
pnpmpnpm add jotai
yarnyarn add jotai

Methods

Overview

Jotai models state as atoms, the smallest units of state. Components read and write atoms directly, and derived atoms compose new values from existing ones, giving fine-grained reactivity without a central store.

Core Methods

atom creates primitive or derived atoms, useAtom reads and writes them in components, and useAtomValue or useSetAtom read or write separately. A store can manage atoms outside React.

Usage Notes

Keep atoms at module scope for sharing, split large state into focused atoms, and use derived atoms for computed values. Reset atoms on unmount when state should not persist.

Common Pitfalls

Creating atoms inside components makes them local and can cause leaks if not handled. Over-granular atoms multiply subscriptions and re-render paths, so group closely related state.

FAQ

How is Jotai different from Redux?
Jotai stores state in independent atoms rather than one central store. Components subscribe to specific atoms, so updates are granular and there is no reducer or action boilerplate.
How do I share state across components?
Define the atom at module scope and import it. Atoms created inside a component are local to that instance, so shared state must live outside the component.
Can atoms depend on each other?
Yes. A derived atom reads other atoms through get, and writable derived atoms can update multiple atoms. This compositional model keeps logic close to where state is defined.