It includes a few improvements. Some utils are rewritten as there was a misconception when migrating from v1. ESM builds are optimized for Vite users.
Migration Guide for jotai/utils
atomWithDefault
// suppose we have this
const asyncAtom = atom(() => Promise.resolve(1))
const countAtom = atomWithDefault((get) => get(asyncAtom))
// and in component
const setCount = useSetAtom(countAtom)
// previously,
setCount((c) => c + 1) // it worked, but it will no longer work
// instead, you need to do this
setCount((countPromise) => countPromise.then((c) => c + 1))
atomWithStorage
// suppose we have async storage
const storage = createJSONStorage(() => AsyncStorage)
const countAtom = atomWithStorage('count-key', 0, storage)
// in component
const [count, setCount] = useAtom(countAom)
// previously, countAtom is a sync atom, so you could update like this:
setCount((c) => c + 1)
// with the new version, it becomes async occasionally, so you need to resolve it:
setCount(async (c) => (await c) + 1)
What's Changed
- breaking(utils): predictable atomWithDefault by @dai-shi in #1939
- breaking(utils): improve atomWithStorage by @dai-shi in #1958
- feat(vanilla): new store listeners for devtools by @dai-shi in #1966
- fix(build): mode env for "import" condition" by @dai-shi in #1978
New Contributors
- @reinierkaper-carewell made their first contribution in #1980
Full Changelog: v2.1.1...v2.2.0