Skip to content

Feature request: async data from useQuery #5270

Answered by TkDodo
denisborovikov asked this question in Ideas
Discussion options

You must be logged in to vote

We are thinking about something like this, mainly to integrate better with suspense and the new use hook, but no decision have been made.

One problem I see by sticking this into useQuery is that on first render, we don't have the promise yet, because it will be kicked off later, when the observer subscribes. This might even be delayed if we are currently restoring from a persister. So, where would we get that asyncData promise from?

Note that you can always call queryClient.fetchQuery() in your handleClick function and await it, and pass a staleTime to it so that it only fetches if data isn't older than that staleTime. If you just want any data, queryClient.ensureQueryData() also works.

Replies: 2 comments 2 replies

Comment options

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

@everythinginjs
Comment options

Answer selected by denisborovikov
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
3 participants