jotai: Jotai async atom not working with expo-router

Summary

It looks like async read atoms are not working well with expo-router No issue using classic expo with App.js. When using expo-router, page is blank.

const countAtom = atomWithAsyncStorage('countAtom', 0)
const count2Atom = atom(async (get) => (await get(countAtom)) * 2)

export const Component = () => {
  const [count] = useAtom(count2Atom)
  console.log(count)
  return <Text>Component {count}</Text>
}

Link to reproduction

https://github.com/smontlouis/jotai-async

Replace package.json “main” entry with either “expo-router/entry” or “node_modules/expo/AppEntry.js” to see jotai not working with expo-router

About this issue

  • Original URL
  • State: closed
  • Created 10 months ago
  • Comments: 18 (9 by maintainers)

Most upvoted comments

What would be an equivalent so that I can try with something else (without jotai) for expo ?

const promise = new Promise((r) => setTimeout(r, 10 * 1000));
let resolved = false;
promise.then(() => { resolved = true; });

const usePromise = () => {
  if (!resolved) { throw promise; }
};

It should give you the blank screen, if my understanding is correct. But, then expo-router team may say that they don’t support Suspense yet.

Omg it’s failing ! Thank you for your time I’ll report to them !