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

Support primitive atoms with a Promise as the initial value. #430

Closed
mhcoffin opened this issue Apr 17, 2021 · 6 comments · Fixed by #431
Closed

Support primitive atoms with a Promise as the initial value. #430

mhcoffin opened this issue Apr 17, 2021 · 6 comments · Fixed by #431
Assignees

Comments

@mhcoffin
Copy link
Contributor

mhcoffin commented Apr 17, 2021

I think this would be a powerful feature. It would allow one to create an atom that is initially suspended, and then un-suspend it later, when data is available. See, for example, a simple subscription example. This was derived from something I was working in for firebase authentication. The same idea would work for firestore subscriptions. Dai-shi also mentioned that atomWithQuery() could be improved if this were supported.

Work-arounds are possible using a combination of atoms and useEffect, but in my experience they're very tricky to get exactly right and they require quite a bit of code.

In addition to the additional power, it seems like it might be better to implement this than try to write documentation explaining why it doesn't work. :-)

@dai-shi
Copy link
Member

dai-shi commented Apr 17, 2021

Thanks for opening this up. This is something I thought about too. Not sure if it can be implemented in a straightforward way. React Suspense contract is to wait until the promise is resolved, right? So, we need to return a new promise. I can try that.

I wonder if anyone has an idea for typing.

@dai-shi
Copy link
Member

dai-shi commented Apr 17, 2021

(Also wondering if this is possibly related with #426. In this case, it's a priority for me.)

Edit: on second thought, this is not related.

@mhcoffin
Copy link
Contributor Author

Accidentally closed this.

@dai-shi
Copy link
Member

dai-shi commented Apr 18, 2021

@dai-shi
Copy link
Member

dai-shi commented Apr 18, 2021

Oh my, the same issue can be reproduced with a normal async read atom.
https://codesandbox.io/s/winter-bash-rp2rr?file=/src/App.js
I think this is a bigger issue and not fixed yet by 8a2c510.

@dai-shi
Copy link
Member

dai-shi commented Apr 18, 2021

the same issue can be reproduced with a normal async read atom.

let me create a new issue.

done: #434

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

Successfully merging a pull request may close this issue.

3 participants