-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Build a new useLoadableQuery
hook
#11349
Comments
useInteractiveQuery
hookuseLoadableQuery
hook
Dear Jerel, This is fantastic, thank you so much. Would it be possible, if it made sense (I am not sure I am writing good code :)), to have a reset function returned alongside refetch and fetchMore that could set the queryRef back to null? The use case is a search field within a pagination component. Best, Lydia |
Hey @LydiaF 👋 Glad to hear you have interest in this hook! The I've gone ahead and updated this issue description to include the |
Woops missed that! But brilliant, thank you so much, looking forward to it! |
Finished in #11300 and will be released in |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This is an umbrella issue to capture the work proposed for the new
useLoadableQuery
hook that we will be introducing in v3.9.Purpose
This hook will work similarly to
useBackgroundQuery
in that it will return aqueryRef
that can be passed touseReadQuery
to suspend and re-render with cache updates. The biggest difference between this hook anduseBackgroundQuery
is that it will require a call to a function to trigger the creation/update to thequeryRef
. This is more suitable when using this style hook in an event handler. This is especially useful when you'd like to start preloading some data based on a user interaction.Here is the proposed API/design of the hook
Advantages over
useBackgroundQuery
While a similar result can be achieved with
useBackgroundQuery
, the ergonomics are a bit clunky due to the fact that it would require you to bring in React state to trigger updates to the hook.As an example, say you have a todo list and would like to start preloading a todo item's details when hovering over its title. With
useBackgroundQuery
, you'd need a combination ofskipToken
and React state to achieve this.With
useLoadableQuery
, this becomes much simplier:Naming
I'm opting to avoid calling this
useLazyBackgroundQuery
primarily because I don't want users to think this works identically touseLazyQuery
. While the use cases are similar, there are two biggest differences between the wayuseLazyQuery
anduseLoadableQuery
works:variables
are not passed to theuseLoadableQuery
hook directly. They can only be set by theloadQuery
function returned from the hook.loadQuery
function returnsvoid
and does not yield any data itself. All data is accessed through thequeryRef
byuseReadQuery
I opted to name this hook in a different in a way that doesn't imply it works similar to
useLazyQuery
. I felt naming ituseLazyBackgroundQuery
might imply similar mechanics, such as the wayuseSuspenseQuery
is designed relative touseQuery
.The text was updated successfully, but these errors were encountered: