ReactMedium

What is Recoil?

Recoil was an experimental state management library from Meta built around atoms (units of shared state) and selectors (derived, possibly async state), with components subscribing to exactly the atoms they use. The project was archived on January 1, 2025 and is no longer maintained, so it should not be used for new projects; Jotai is the closest actively maintained alternative.

Concepts it introduced

  • Atoms: atom({ key: "count", default: 0 }), readable and writable from any component with useRecoilState.
  • Selectors: derived state from atoms or other selectors, including async selectors that integrate with Suspense.
  • Atom families: parameterized atoms (one per item ID).
  • RecoilRoot provider at the top of the app.
  • Fine-grained subscriptions: only components using a changed atom re-render.

Why it stalled

It stayed at 0.x for years, had limited support for React 18 concurrent features, and Meta stopped investing in it publicly. The repository is now read-only.

What to use instead

  • Jotai: the same atom-based model with a smaller API, no string keys, active maintenance (version 3 in 2026, React 18+). atom(), useAtom(), useAtomValue(), useSetAtom().
  • Zustand: a single store with selectors.
  • Redux Toolkit: structured global state.
  • TanStack Query: for async server data previously modeled with async selectors.

Interview tip

Explain atoms and selectors, then mention that Recoil is archived and how you would migrate (usually to Jotai).

Code example

tsx
1// Recoil (archived, shown for reference)
2// const countState = atom({ key: "count", default: 0 });
3// const doubled = selector({ key: "doubled", get: ({ get }) => get(countState) * 2 });
4// <RecoilRoot><Counter /></RecoilRoot>
5
6// Jotai: the maintained atom-based equivalent (no keys, no required provider)
7import { atom, useAtom, useAtomValue } from "jotai";
8
9const countAtom = atom(0);
10const doubledAtom = atom((get) => get(countAtom) * 2); // derived, like a selector
11
12const userIdAtom = atom("1");
13const userAtom = atom(async (get) => {
14 const res = await fetch(`/api/users/${get(userIdAtom)}`); // async derived atom, suspends
15 return (await res.json()) as { name: string };
16});
17
18export function Counter() {
19 const [count, setCount] = useAtom(countAtom);
20 const doubled = useAtomValue(doubledAtom);
21 return <button onClick={() => setCount((c) => c + 1)}>{count} (x2 = {doubled})</button>;
22}
23
24export function UserName() {
25 const user = useAtomValue(userAtom); // wrap in <Suspense>
26 return <span>{user.name}</span>;
27}

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the React set.

Open in study app