Derived & Async Atoms
Compose atomic state dynamically and trigger native React Suspense with promises.
Composition & Promises
A Derived Atom is created by passing a read function (get) => ... to atom(). By calling get(anotherAtom) inside this function, Jotai establishes a dynamic, runtime dependency graph.
An Async Atom is simply a derived atom whose read function returns a Promise (async (get) => ...).
No More useEffect
In standard React, coordinating dependent state variables or firing network requests when an ID changes often results in spaghetti useEffect chains.
Jotai handles this reactivity graph for you. When a base atom updates, any derived atoms automatically re-evaluate. If that evaluation is a fetch request, it happens seamlessly.
Native React Suspense
When a React component calls useAtomValue() on a pending Async Atom, Jotai automatically throws the Promise to React.
This triggers the nearest <Suspense> boundary natively, allowing you to build loading states without manually tracking isLoading or isError flags in your global store.
Interactive Lab: Async Suspense
Use the controls to change the User ID. The async atom will automatically refetch, trigger React Suspense, and animate the UI!
Click Next User. Jotai updates the base atom, re-evaluates the derived async atom, and throws the pending Promise to React's native Suspense boundary!
Check yourself
Pick an answer to lock it in, then read why. Getting one wrong is part of how it sticks.
Remember this
- Derived atoms are created by passing a function
(get) => ...toatom(). - Jotai tracks dependencies dynamically at runtime on every evaluation.
- Async Atoms are just derived atoms that return a Promise.
- Jotai natively suspends components while Async Atoms are pending.
Done with this concept?
Mark it complete to track your progress. No login needed.