-
-
Notifications
You must be signed in to change notification settings - Fork 642
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
feat(query): atomWithQuery to use options.initialData to avoid suspense #548
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/pmndrs/jotai/J5Jh72RbZ5PLb7KHWvKG4Y6WHEca |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit a7eb6bc:
|
6ecf7d9
to
2cb8af6
Compare
ab2f313
to
2897265
Compare
a016d0c
to
dbebd88
Compare
Currently, it's TS limitation. microsoft/TypeScript#37663 |
@aulneau Pushed a commit. Note that this breaks the note in the official docs.
It will be twice. |
Nice, just tested this out and works the same as what I had. For my own curiosity, why did you prefer to do this over the atomWithDefault? |
atomWithDefault has two atoms internally (which overlaps with Furthermore, the grand rule of mine is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are fine with breaking the official note. It's OK for me.
Ah makes sense! I'm fine with it, I personally have never used the function version of initial data. I'd be curious to see how it might be problematic if it fires twice. Let's cross that bridge when or if we come to it. Thanks for updating the implementation! |
@dai-shi would a merge be possible soon? Thanks 🙏 |
This updates the initial atom used for data for the query atom to be
atomWithDefault
and uses the initialData value if present for that. This is helpful because if data is passed, the query atom will not be suspense/async by default. This is very helpful in the context of SSR where suspense is not well supported yet.@dai-shi curious what you think, I've tested this locally and it works well. The last thing I'd like to do is pass
get
to the initialData function, what do you think?Also this type error I am not sure how to fix yet: