-
Notifications
You must be signed in to change notification settings - Fork 27
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
feature: added useSuspenseQuery
hook to react package
#353
Conversation
🦋 Changeset detectedLatest commit: 4126515 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Can you add tests for this?
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.
I haven't tested yet, but looks great overall
LGTM |
e2e68e2
to
c1f96ac
Compare
# Conflicts: # pnpm-lock.yaml
FYI @rkistner @DominicGBauer : I made a few changes to the PR so that the |
This PR aims to introduce the
useSuspenseQuery
hook to thereact
package so that users can handle the loading state of a query with Suspense instead of the conventionalisLoading
/isFetching
state variables.The implementation is a minor variation of #100. The most noteworthy iterations are that it adds the suspense support under a separate hook to
useQuery
, it supports queries that take longer than 5 seconds to complete, and compilable queries are accepted as possible input as well.As mentioned in the former PR, the state of the hook needs to be managed outside of the hook due to state being discarded while a component is suspended. This means that state is cached based on a
query-parameters-options
key which means multiple hook invocations on the same would resolve to the same query. Note that the state for a given key is disposed when the hook is destroyed, but this opens the door for potential future work to add proper query caching to bothuseQuery
anduseSuspenseQuery
- with a proper interface for managing this cache (which is something that Tanstack supports really well).A few examples have been added to the package's README.md to illustrate how to handle typical cases when using Suspense, such as blocking navigation while the target page's components are suspending.