useQuery vs useSuspenseQuery

I'm having a hard time understanding in what's the main difference between useQuery and useSuspenseQuery? For example I prefetch one endpoint at page.tsx, considering that prefetch will prefill the cache then what will happen if I call useQuery instead on useSuspenseQuery? Also if a component is using useSuspenseQuery for some data, then how to invalidate that and fetch new data from some other component? With useQuery we do have invalidate function that I can call!
9 Replies
Neto
Neto4d ago
useSuspenseQuery handles the interaction with suspense boundaries
Neto
Neto4d ago
– React
The library for web and native user interfaces
Mainak
Mainak3d ago
I understand that, but my question is specifically regarding to the default template for t3 app. We are using useSuspenseQuery but there is no suspense boundary around! Also we are prefetching the request with void which wont wait for the request to succeed
Neto
Neto3d ago
next has implicit suspense boundaries (app dir)
Mainak
Mainak3d ago
But isn’t suspense boundary is only created when we add loading.tsx?
Neto
Neto3d ago
there should be some level of streaming with suspense, otherwise the page will be awful you can always not use suspense queries and do full side client queries
Mainak
Mainak3d ago
So if I prefetch on the server and use suspense query in the client, then I do need to wrap that component with suspense for it to show loaders?
NekoChan
NekoChan3d ago
Advanced Server Rendering | TanStack Query React Docs
Welcome to the Advanced Server Rendering guide, where you will learn all about using React Query with streaming, Server Components and the Next.js app router. You might want to read the Server Rendering & Hydration guide before this one as it teaches the basics for using React Query with SSR, and Performance & Request Waterfalls as well as Pre...
Mainak
Mainak3d ago
I’ve gone through this, but as I said it’s kinda unclear for me!
Want results from more Discord servers?
Add your server