Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant