Skip to content
This repository has been archived by the owner on Jan 1, 2025. It is now read-only.

[Question]how to return extra info with async atom #2301

Open
feiyin0719 opened this issue Jan 21, 2024 · 0 comments
Open

[Question]how to return extra info with async atom #2301

feiyin0719 opened this issue Jan 21, 2024 · 0 comments

Comments

@feiyin0719
Copy link

feiyin0719 commented Jan 21, 2024

I use async Selector, I want to return extra info when the atom in loading state, how should I implement it?
it seems when in loading state, the content cannot inclue extra info.
image
I can return like this, the data is promise, this is too ugly , I need to await in Component to fetch the data
return { query,data:getData(get(queryAtom)) }
like this:

const queryAtom = atom({
  key: "query",
  default: ""
});
const dataAtom = selector({
  key: "data",
  get: async ({ get }) => {
    // I want to return some extra info before fetching data, how to return this? 
    const data = await getData(get(queryAtom));
    return data;
    // I can return like this, the data is promise, this is too ugly , I need to await in Component to fetch the data
    // return { query,data:getData(get(queryAtom)) } 
  }
});
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant