Skip to content

v2.2.0

Compare
Choose a tag to compare
@dai-shi dai-shi released this 12 Jun 11:03
· 284 commits to main since this release

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

Full Changelog: v2.1.1...v2.2.0