Overview
Jotai v1 was released in June 2022. After gathering feedback from the community and with React’s proposal for first-class promise support, Jotai v2 brings a refined API with breaking changes and new capabilities. RFC: GitHub Discussion #1514New Features
Vanilla Library
Jotai now provides vanilla (non-React) functions and React functions separately through alternate entry points:jotai/vanilla for better tree shaking.
Store API
Jotai now exposes a store interface for directly manipulating atom values:Flexible Write Function
The write function now accepts multiple arguments and can return a value:Breaking Changes
Async Atoms Are No Longer Special
Async atoms are now just normal atoms with promise values. Theget function in atom read functions does not resolve promises.
However, the useAtom hook continues to resolve promises for convenience.
Some utilities like splitAtom expect sync atoms and won’t work with async atoms directly.
Migration Example
v1 API:await or .then() where needed.
Writable Atom Type (TypeScript)
TheWritableAtom type signature has changed:
v1:
WritableAtom type directly. Let TypeScript infer types from your atom definitions.
Removed Functions
Provider’s initialValues Prop
v1 API:
Provider’s scope Prop
v1 API:
abortableAtom Util
The abort signal functionality is now included by default in atoms.
v1 API:
waitForAll Util
Use native Promise.all() instead.
v1 API:
splitAtom with Async Atoms
The splitAtom utility only accepts sync atoms. Unwrap async atoms before passing them.
v1 API:
loadable for more control over loading states, or use the atoms-in-atom pattern for Suspense support.
Resources:
Additional Changes
Utils
atomWithStorage
The delayInit option is removed and is now the default behavior.
atomWithStorage will always render initialValue on the first render, and the stored value (if any) on subsequent renders. This behavior differs from v1.
See: Discussion #1737
useHydrateAtoms
This hook can only accept writable atoms.
Import Paths
The v2 API is available from alternate entry points for library authors and non-React users:jotai/vanilla- Core atom functions without Reactjotai/vanilla/utils- Vanilla utilitiesjotai/react- React hooksjotai/react/utils- React utilities
Migration Checklist
- Update async atom read functions to use
awaitor.then() - Replace
ProviderinitialValueswithuseHydrateAtoms - Replace
Providerscopewith custom context and store - Remove
abortableAtomwrapper (use plainatom) - Replace
waitForAllwithPromise.all() - Unwrap async atoms before passing to
splitAtom - Update TypeScript types if using
WritableAtomdirectly - Update
atomWithStorageusage if relying on v1 initialization behavior - Review and update import paths for better tree shaking
Getting Help
If you encounter issues during migration:- Check the GitHub Discussions
- Join the Discord community
- Review the official documentation
- Open an issue on GitHub