Atoms: The Unit of State in Jotai
Create primitive atoms with atom() and understand how Jotai's Provider-less design differs from Context.
Atoms: The Unit of State in Jotai is a free React Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the React Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What is an Atom?
In Jotai, state is broken into atoms: small, independent pieces of reactive state. Each atom holds a single value and is created outside of components with atom(initialValue).
This mirrors the mental model of splitting state into the smallest meaningful units, rather than one large store object.
Atoms are Reactive
When an atom's value changes, only the components that subscribed to that specific atom re-render. Components that read other atoms are unaffected.
This fine-grained reactivity is Jotai's core advantage over React Context, which re-renders all consumers on any change.
Creating Atoms Outside Components
Define atoms at the module level: const countAtom = atom(0). This ensures the atom identity is stable across renders and the atom is not re-created on each component mount.
Atoms are lightweight references; they do not hold their own value. The value lives in the Jotai store.
Provider-Less by Default
By default, Jotai uses an implicit global store. You do not need to wrap your app in a Provider to start using atoms, which makes adoption simple in existing projects.
Atoms are globally accessible from any component in the tree without any prop drilling or context threading.
Explicit Provider for Scoped State
When you need multiple independent instances of the same component tree (e.g., two separate forms, each with their own form state atoms), wrap each in a Jotai Provider. Each Provider creates an isolated store.
This is useful for micro-frontend architectures or complex page layouts with independent state islands.
Global Store vs Scoped Store
The global store persists atoms for the lifetime of the application. A scoped Provider store resets when the Provider unmounts, which is perfect for modal dialogs or page-level state that should not persist globally.
You can even pass a custom store instance to Provider for server-side rendering isolation.
Jotai vs Zustand Comparison
Zustand uses a single store object with selectors to prevent unnecessary re-renders. Jotai divides state into atoms, and each component subscribes only to the atoms it reads.
Jotai is more natural for fine-grained UI state (individual input values, toggle flags). Zustand fits well for larger, interconnected application state.
Jotai vs React Context
React Context re-renders every consumer component whenever the context value changes, even if the consuming component only cares about one field in the context object.
Jotai solves this: a component using useAtom(nameAtom) only re-renders when nameAtom changes, not when any other atom changes.
Atom Identity and Equality
Jotai uses Object.is comparison by default to determine if an atom's value has changed. If you set an atom to the same value it already holds, no re-render is triggered.
For complex objects, use the selectAtom utility to derive a stable primitive from a large atom, preventing re-renders when unrelated fields change.
Atoms vs useState
useState is local to a single component. Atoms are shared across the entire component tree without explicit passing. When two sibling components read the same atom, they automatically stay in sync.
This eliminates the need to lift state up for cross-component sharing while keeping re-renders minimal.
Practical Atom Examples
Typical atoms: const themeAtom = atom('light'), const cartItemsAtom = atom([]), const selectedUserIdAtom = atom(null). These are defined once and imported anywhere in the application.
Each atom is independent: updating cartItemsAtom does not trigger re-renders in components that only read themeAtom.
Jotai vs Context Re-render Behavior
How does Jotai differ from React Context in terms of re-rendering?
Lesson Recap
Atoms are the fundamental unit of state in Jotai, created with atom(initialValue) outside components and shared across the tree without Provider by default. When an atom changes, only its subscribers re-render.
This fine-grained reactivity is Jotai's key advantage over React Context, and its per-atom subscription model differs from Zustand's single-store approach.
Frequently asked questions
Is the “Atoms: The Unit of State in Jotai” lesson free?
Yes — the full text of “Atoms: The Unit of State in Jotai” is free to read here on the web, and the React Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the React Academy course, upgrade to CoddyKit PRO.
What will I learn in “Atoms: The Unit of State in Jotai”?
Create primitive atoms with atom() and understand how Jotai's Provider-less design differs from Context. You practise React Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start React Academy?
No prior experience is required. React Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Atoms: The Unit of State in Jotai” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this React Academy lesson?
Yes. Every React Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Atoms: The Unit of State in Jotai
- Reading and Writing Atoms with useAtom
- Derived Atoms and Async Atoms
- Jotai vs Zustand vs Context: When to Use Which