Skip to content

Derived atoms of ✨potentially asynchronous✨ atoms. #2640

Answered by dai-shi
iwoplaza asked this question in Ideas
Discussion options

You must be logged in to vote

Thanks for opening up a discussion.

This dual nature is nice (concrete value or a promise) because derived atoms could process the value in sync if it is available, and fallback to awaiting and returning a Promise if it is not.

Yes, this is pretty interesting. I knew this was possible and thought it's kind of advanced usage.

However, handling those cases looks to be more trouble that it is worth, so the easiest is to just always await.

Exactly.

causing tiny loading states and unnecessary remounts.

Exactly.

Below is an atom that handles both cases separately (processes the data in sync if it is available, returns a promise otherwise).

I'm so glad to see you've reached there. I thin…

Replies: 3 comments 3 replies

Comment options

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

@dai-shi
Comment options

Answer selected by iwoplaza
Comment options

You must be logged in to vote
1 reply
@iwoplaza
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
4 participants