Skip to content

apollo async atom #1069

Closed Answered by mzalevski
mzalevski asked this question in Q&A
Mar 21, 2022 · 2 comments · 5 replies
Discussion options

You must be logged in to vote

ok, thanks to 2 insights:

  1. Atom logic is outside React, so you can't use hooks in get function.
  2. if you give an atom a promise, jotai will suspend and handle it for you

I figured it out. see: https://github.com/mzalevski/jotai-apollo

export const currentCountryAtom = atom<Promise<Country>>((get) => {
  return get(clientAtom)
    .query<{ country: Country }>({ query: COUNTRY })
    .then((result) => result.data.country);
});

thanks @dai-shi @Aslemammad

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
5 replies
@Aslemammad
Comment options

@mzalevski
Comment options

@mzalevski
Comment options

@Aslemammad
Comment options

@Aslemammad
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by mzalevski
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants