# Atomic State (Jotai)

> Move from a top-down monolithic store to bottom-up, granular atomic state.

Subject: State Management | Lesson 19 of 22 | 6 min read
Interactive lesson: https://codewithanimation.in/state-management/atomic-state-jotai
Previous: [Context, Guards, & Actions](https://codewithanimation.in/state-management/xstate-context-and-actions.md) | Next: [Derived & Async Atoms](https://codewithanimation.in/state-management/jotai-derived-and-async-atoms.md)

## What is an Atom?

In Jotai, an 'atom' is an immutable configuration object that defines a piece of state. It does not hold the state value directly; rather, it acts as a unique reference key used by the Jotai Store to track the runtime value.

Atoms are the minimal, granular building blocks of state. Instead of defining one massive global object, you define tiny, independent atoms (`userAtom`, `themeAtom`) exactly where you need them.

## Top-Down vs Bottom-Up

Monolithic stores (Redux, Zustand) are Top-Down. You define a giant state tree upfront and write selector functions to slice data downward into your components.

Atomic state is Bottom-Up. You create small atoms and compose them upward. State scales dynamically and naturally with your component structure.

## Granular Reactivity

Because each atom is its own isolated slice, subscribing to an atom via `useAtom()` guarantees perfect render optimization without writing any selector boilerplate.

If Component A subscribes to `themeAtom` and Component B subscribes to `cartAtom`, updating the cart will mathematically never trigger a re-render in Component A.

## Common mistake: The Selector Fatigue

In monolithic stores, passing a shared object (e.g. `{ user, theme, cart }`) means that any update to `cart` causes every component consuming the store to re-render, unless you manually write selectors for everything.

In Jotai, atoms *are* the minimal selectors. The overhead of unrelated updates is completely eliminated.

## Tip: Stateless Definitions

Remember that `const countAtom = atom(0)` does not execute or store `0` inside `countAtom`. It merely creates a static blueprint.

The actual value `0` lives inside the implicit global Jotai Store, keyed by the `countAtom` reference.

## Try it: Infographic: Top-Down vs Bottom-Up

Review the diagram below comparing the data flow of a monolithic store against granular atoms.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/state-management/atomic-state-jotai

## Check yourself

### Question 1

What is the fundamental architectural difference between a monolithic store (Zustand) and atomic state (Jotai)?

- A. Zustand uses React Context, while Jotai bypasses React entirely.
- B. Zustand is Top-Down (one central store sliced downward), while Jotai is Bottom-Up (independent atoms composed upward).
- C. Zustand supports async actions, while Jotai atoms are strictly synchronous.

Correct answer: B

Jotai's bottom-up approach means you don't need a central schema. You just create independent atoms and use them wherever they are needed, achieving granular reactivity by default.

- Why not A: Both can use Context or work outside of it.
- Why not C: Jotai fully supports async atoms natively.

## Remember this

- An atom is an immutable configuration object, not a mutable data container.
- Atomic state is a Bottom-Up architecture, contrary to the Top-Down monolith.
- Subscribing to a specific atom guarantees you will never re-render from unrelated state changes.
- Atoms act as their own minimal selectors, eliminating boilerplate.
