Skip to main content
← Guides

Guide

Recoil vs Jotai 2026: Atomic State Management Compared

Updated PkgPulse Team10 min read
0

Recoil is effectively abandoned by Meta. Jotai is the maintained, lighter alternative with a nearly identical API. Full comparison of atomic state models.

Contents

TL;DR

Choose Jotai for new React code that needs shared atomic state. Recoil's repository is archived. If you already use Recoil, start by migrating a group of atoms and selectors together. Test async loading, resets, and any snapshot-dependent behavior before removing the old store. Recoil repository

Key Takeaways

  • Recoil's repository is archived. Plan a migration when you can test the affected state together.
  • Jotai 3 ships only ES modules. Before upgrading, check that your app, test runner and build can load its ESM exports and that TypeScript is at least 5.5. If your project still needs an older compiler or a separate CommonJS build, keep the v2 package pinned while you update the toolchain. Jotai 3 keeps the atom model and moves atomFamily into jotai-family. Replace removed loadable imports with an unwrap-based read or a Suspense boundary. Jotai v3 migration guide
  • Both use atoms. Migrate base atoms and derived values first. Review atom families, async selectors, and snapshots separately.
  • Jotai has an active ecosystem — utilities, Immer integration, Zustand bridge, React Query integration
  • Recoil has known React 18 bugs that are unlikely to be fixed

The Atomic State Model

The atomic model solves a real React problem. Traditional global stores (Redux, Zustand) hold all state in one store object. Components subscribe to the whole store (or large slices of it) and re-render when anything in that slice changes.

Atoms are different: each piece of state lives in its own independent atom. Components subscribe to exactly the atoms they need. When an atom changes, only the components that depend on that atom re-render.

Traditional store model:
  Store
    ├── users: User[]        ← UserList and UserCount both re-render
    ├── posts: Post[]           when any user changes
    └── settings: Settings

Atomic model:
  usersAtom: User[]          ← UserList subscribes; re-renders when users change
  postsAtom: Post[]          ← PostList subscribes; re-renders when posts change
  settingsAtom: Settings     ← SettingsPanel subscribes; completely isolated

The key benefit is granular subscriptions: a component that uses settingsAtom never re-renders when usersAtom changes. This matters in large apps with many top-level state pieces.

Derived state (selectors) also fits naturally: a derived atom computes from other atoms and automatically updates when its dependencies change, without any subscription setup.


Why Recoil Has Problems

Recoil was introduced at React Europe 2020 and had a strong initial reception. The atomic model resonated with the React community. But Meta's internal priorities diverged from open-source maintenance:

Recoil development timeline:
  2020: Open sourced — great community reception
  2021: Active development, growing adoption
  2022: Releases slow down, community raises concerns
  2023: Recoil 0.7.7 published
  2025: Repository archived

The specific problems that have not been fixed:

  • Atom keys must be globally unique strings — a footgun that causes hard-to-debug production errors when code splitting is involved
  • Some useRecoilValue usages trigger extra re-renders in React 18 concurrent mode (StrictMode double-render issues)
  • No first-class TypeScript inference without explicit type annotations on every atom
  • The selector API has a steeper learning curve than it needs to be

The archived repository and its issue history are available to read when auditing an existing Recoil app.


API Comparison

The APIs are similar enough that migration is mostly mechanical:

// Recoil — requires RecoilRoot provider + unique string keys
import { RecoilRoot, atom, selector, useRecoilState, useRecoilValue } from 'recoil';

// 1. Must wrap app in RecoilRoot
function App() {
  return <RecoilRoot><MyApp /></RecoilRoot>;
}

// 2. Define atoms — key must be globally unique
const cartItemsAtom = atom<CartItem[]>({
  key: 'cartItems',   // Unique string key required — duplicates cause runtime errors
  default: [],
});

// 3. Derived state uses a separate 'selector' concept
const cartTotalSelector = selector<number>({
  key: 'cartTotal',   // Also must be globally unique
  get: ({ get }) => {
    const items = get(cartItemsAtom);
    return items.reduce((sum, item) => sum + item.price * item.quantity, 0);
  },
});

// 4. Use in components
function CartSummary() {
  const [items, setItems] = useRecoilState(cartItemsAtom);
  const total = useRecoilValue(cartTotalSelector);
  return <div>Total: ${total.toFixed(2)} ({items.length} items)</div>;
}
// Jotai — no provider required, no string keys
import { atom, useAtom, useAtomValue, useSetAtom } from 'jotai';

// 1. No provider needed for default global store
//    (use <Provider> only for isolated stores in tests or nested apps)

// 2. Define atoms — no key required, no strings to manage
const cartItemsAtom = atom<CartItem[]>([]);

// 3. Derived atoms are just atoms with a getter — no separate concept
const cartTotalAtom = atom((get) => {
  const items = get(cartItemsAtom);
  return items.reduce((sum, item) => sum + item.price * item.quantity, 0);
});

// 4. Same hook names, nearly identical usage
function CartSummary() {
  const [items] = useAtom(cartItemsAtom);
  const total = useAtomValue(cartTotalAtom);
  return <div>Total: ${total.toFixed(2)} ({items.length} items)</div>;
}

The Jotai version is cleaner in several ways: no string keys to manage, no RecoilRoot required, and derived state is expressed as a plain atom rather than a separate selector abstraction.


Converting a Recoil Codebase to Jotai

The migration is largely mechanical. A codebase search-and-replace covers most of it:

// BEFORE (Recoil):
import { atom, selector, useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';

const textAtom = atom({
  key: 'text',
  default: '',
});

const upperCaseSelector = selector({
  key: 'upperCaseText',
  get: ({ get }) => get(textAtom).toUpperCase(),
});

function TextInput() {
  const [text, setText] = useRecoilState(textAtom);
  const upper = useRecoilValue(upperCaseSelector);
  return <input value={text} onChange={e => setText(e.target.value)} />;
}
// AFTER (Jotai):
import { atom, useAtom, useAtomValue } from 'jotai';

// Remove { key, default: ... } wrapper — just pass the default value directly
const textAtom = atom('');

// selector → derived atom (atom with getter function)
const upperCaseAtom = atom((get) => get(textAtom).toUpperCase());

function TextInput() {
  // Hook names:
  // useRecoilState     → useAtom       (same shape: [value, setter])
  // useRecoilValue     → useAtomValue  (read-only)
  // useSetRecoilState  → useSetAtom    (write-only)
  const [text, setText] = useAtom(textAtom);
  const upper = useAtomValue(upperCaseAtom);
  return <input value={text} onChange={e => setText(e.target.value)} />;
}

// Provider changes:
// Remove <RecoilRoot> entirely — Jotai works without a provider
// OR replace with <Provider> (jotai) for isolated stores

The main non-mechanical parts of migration:

  • Atom families can move from Recoil's atomFamily({ key, default }) to atomFamily((id) => atom(initialValue)) from jotai-family in Jotai 3. The initializer should use the ID if the atom's initial value depends on it.
  • Async selectors: Recoil's async selectors → Jotai's async atoms with Suspense (same pattern, cleaner API)
  • Snapshots: Recoil's useRecoilSnapshot has no direct equivalent in Jotai, but is rarely used

Jotai's Utility Library

These examples show storage, reset, and async reads in Jotai 3. The async example uses unwrap to show a loading fallback. Handle rejection with a React error boundary around the component.

// Persist atom to localStorage — syncs across browser tabs
import { atomWithStorage } from 'jotai/utils';

const themeAtom = atomWithStorage<'light' | 'dark'>('theme', 'light');
// Read: synced from localStorage on mount
// Write: saves to localStorage, triggers storage event for other tabs

// Reset atom to its default value
import { atomWithReset, useResetAtom } from 'jotai/utils';

const filterAtom = atomWithReset('all');

function FilterReset() {
  const reset = useResetAtom(filterAtom);
  return <button onClick={reset}>Clear filters</button>;
}

// Show a loading fallback without suspending this component.
import { atom, useAtomValue } from 'jotai';
import { unwrap } from 'jotai/utils';

const userAtom = atom(async () => {
  const res = await fetch('/api/user');
  if (!res.ok) throw new Error('Failed to fetch user');
  return res.json() as Promise<{ name: string }>;
});

const userOrLoadingAtom = unwrap(userAtom, () => null);

function UserDisplay() {
  const user = useAtomValue(userOrLoadingAtom);
  if (user === null) return <Spinner />;
  return <div>{user.name}</div>;
}

Async Atoms and Suspense

Use a Suspense boundary when you want React to handle pending reads. After a successful write, increment a dependency of the read atom to trigger a refetch. The example assumes your app supplies the user endpoints and handles write errors in the UI.

// Illustrative async read with invalidation after a successful write.
import { atom, useAtomValue, useSetAtom } from 'jotai';

const refreshUserAtom = atom(0);

const userAtom = atom(async (get) => {
  get(refreshUserAtom);
  const res = await fetch('/api/user');
  if (!res.ok) throw new Error('Failed to fetch user');
  return res.json() as Promise<User>;
});

// Write atom that makes API call
const updateUsernameAtom = atom(
  null,
  async (get, set, newUsername: string) => {
    const currentUser = await get(userAtom);
    const res = await fetch(`/api/users/${currentUser.id}`, {
      method: 'PATCH',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ username: newUsername }),
    });
    if (!res.ok) throw new Error('Failed to update username');
    set(refreshUserAtom, (revision) => revision + 1);
  }
);

function UserProfile() {
  const user = useAtomValue(userAtom); // Suspends until resolved
  const updateUsername = useSetAtom(updateUsernameAtom);

  return (
    <div>
      <span>{user.name}</span>
      <button onClick={() => updateUsername('newname')}>Rename</button>
    </div>
  );
}

// Wrap in Suspense:
<Suspense fallback={<Spinner />}>
  <UserProfile />
</Suspense>

Jotai vs Zustand: Choosing the Right Atom Store

Both Jotai and Zustand are excellent, and both come from the same Pmndrs developer collective. The choice between them is conceptual:

DimensionJotaiZustand
Mental modelAtom-per-value (granular)Store-per-feature (grouped)
Re-render granularityPer-atomPer-selector
Global state organizationMany small atomsFew larger stores
Async stateFirst-class (async atoms)Async in actions
Best forComponent-adjacent stateFeature/domain state

If your state is naturally atomic — theme preference, modal open/closed, selected tab, hover states — Jotai fits perfectly. If your state is naturally grouped — all cart state together, all user state together — Zustand is the more natural fit.


Bundle Size

Measure the compressed production bundle for the same route before and after migration. Include any extra utilities and integrations you import. Compare the route's output with its existing dependencies so shared chunks count only once.


Package Health

Packagenpm versionWhat to check
jotai3.1.0Check Node 22.12+, React 18+, TypeScript 5.5+ for typed projects, and tooling that can load ESM.
recoil0.7.7The repository is archived. Test your existing dependency and React combinations before migrating.
zustand5.1.0Consider this if state is grouped by feature and components select pieces of the store.

When to Choose

Choose Jotai when:

  • Starting any new project that needs atomic state management
  • Currently on Recoil and experiencing React 18 issues or stale dependencies
  • You want atomic state management that is actively maintained
  • You have measured a bundle savings for the routes that use your state store
  • You want async atoms with first-class Suspense support
  • You like the atom-per-value mental model

Consider Zustand instead of Jotai when:

  • Your state is better organized by feature/domain than by individual value
  • You want a simpler mental model — one store with methods
  • You don't need per-atom re-render granularity

Stay on Recoil only when:

  • You have a very large codebase with hundreds of atoms and migration cost is prohibitive
  • Everything works and you are not using React 18 concurrent mode features
  • You have significant internal tooling built around Recoil's snapshot API

The React team's direction is worth considering when choosing between atomic state managers. React Server Components and the emerging patterns around React's concurrent features push state management toward the server — more state lives in the server component tree, fewer atoms are needed on the client. Jotai's lighter footprint aligns better with this direction than Recoil's heavier feature set. Atomic state at the client level is increasingly reserved for genuinely interactive, client-only state: UI toggles, form input, optimistic updates — not application data that can live closer to the server.

For teams on React 18 or 19 with App Router patterns, the pragmatic question is often whether atomic state management is necessary at all. Many React applications that previously needed Recoil or Jotai for cross-component state can achieve the same result with React's built-in useContext plus useReducer, or with React Query's client state features for server-synchronized state. Jotai is the right choice when you have genuinely complex client-only state with fine-grained re-render requirements; for everything else, simpler solutions often suffice. Its minimal API surface means the learning curve is genuinely short, onboarding new developers is straightforward, and there is no risk of the over-engineered Redux antipatterns that caused many teams to seek lighter alternatives in the first place.

Use atomic state for shared client values that change independently, such as drag state or field-level form state. Use component state for values local to one component. Keep server data in your data-fetching layer when it already handles caching and refetching.

For a family keyed by a user ID, start with atomFamily((id: string) => atom(initialValueFor(id))) from jotai-family. Test that two reads for the same ID use the same atom and that distinct IDs keep separate values. If Recoil stored a value in browser storage, check the initial read, reset, and cross-tab update after moving it to atomWithStorage.