Skip to content

How to use async atom in atomsWithQuery jotai v2? #21

Description

@devnomic

Now it returns typing error

const idAtom = atom(async (get) => {
  await new Promise((resolve) => setTimeout(resolve, 100));
  return 1;
});

// Typing error here because of using async
// I need async to await get id from atom id
const [userAtom] = atomsWithQuery(async (get) => {
  const id = await get(idAtom);
  return {
    queryKey: ["getUser", id],
    queryFn: async () => await fetch("https://reqres.in/api/users/" + id)
  };
});

Reproduction link:
https://codesandbox.io/s/nifty-kirch-sg309h?file=/src/App.tsx

Screen Shot 2023-02-02 at 19 54 48

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions