await query without fetching it
I have a component that uses a
useQuery for a given query.
In order to handle user input, I need to use that data. I don't want to just error in the event that the data is not yet fetched, or discard the input.
I know I can just use await queryClient.fetchQuery(blah) in the user input handler. but my understanding is that this will make a second network request, if the first one (from the hook) hasn't returned yet. is that true? I know it won't if there's already data that isn't stale.2 Replies
vicious-gold•3y ago
you probably want this: https://tanstack.com/query/v4/docs/react/guides/disabling-queries#lazy-queries
Disabling/Pausing Queries | TanStack Query Docs
If you ever want to disable a query from automatically running, you can use the enabled = false option.
When enabled is false:
implicit-limeOP•3y ago
I think I was just wrong that a second network request would be made. Thanks!