Good practice for server-side data fetching: suspense vs refetch #9725
Unanswered
gbyesiltas
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey everyone,
We are using tanstack/query in a nuxt project. My question will be related to the difference between the
refetch
andsuspense
functions in a specific setting, but let me give some context:For suspending a network query on the server-side, the docs advice using:
However, I noticed that
useQuery
, as long as it is enabled, will always trigger the queryFn on the server-side; meaning if we don't suspend it, will just cause us to have a bunch of floating network requests.So, I wanted to add a global
enabled
option for the vueQuery instance toenabled: import.meta.client
. In this approach, we fix the unnecessary network calls. Though for the occasions where we do want the suspense behaviour, we have two options:Now, I'm a bit torn between these two options, and I feel like one thing I'm missing is the difference between
suspense
andrefetch
. So, in this context, what do you guys think would be a better way to go?Thanks!
Beta Was this translation helpful? Give feedback.
All reactions