Skip to content

Get promise from async atom to pass into Suspense-aware component? #2293

Answered by dai-shi
QWu4xYV asked this question in Q&A
Discussion options

You must be logged in to vote

When we designed the hook api, and even for now, use isn't officially available. So, such usage is out of the scope. The canonical usage is to use useAtom where you want to consume an atom and suspend.

Alternatively, you can store a promise in an object (or an array) as an atom value:

const anAtom = atom({ promise: Promise.resolve(1) });

fwiw, Valtio v2 API will be designed with use in mind. pmndrs/valtio#810

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@QWu4xYV
Comment options

@dai-shi
Comment options

Answer selected by QWu4xYV
Comment options

You must be logged in to vote
1 reply
@dai-shi
Comment options

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