T
TanStack•7mo ago
vicious-gold

Is it a bad practice to call `useQuery` in route components?

I wonder why we need loader in the first place. Can we just call useQuery and call it a day?
16 Replies
sunny-green
sunny-green•7mo ago
you can certainly to so however you won't benefit from preloading
vicious-gold
vicious-goldOP•7mo ago
So the benefit of using loader instead of useQuery is loading data before rendering route components?
sunny-green
sunny-green•7mo ago
not the only one but yes
vicious-gold
vicious-goldOP•7mo ago
Thanks, would you point me to docs where I can find other benefits of loader?
metropolitan-bronze
metropolitan-bronze•7mo ago
So that is really useful for preloading to have loader. Because when you hover over link the loader function is executed as I understand, right? Not only route js bundle is fetched but data it needs too.
vicious-gold
vicious-goldOP•7mo ago
Which means, I hover over a link to PageA then loader on PagaA route is called automatically?
metropolitan-bronze
metropolitan-bronze•7mo ago
Yes, when you have preload set to intent in your config. That seems petty nice stuff. Just adding preload intent and loaders to your routes and your website feels fast as hell
vicious-gold
vicious-goldOP•7mo ago
Good to know, thanks @Valerka ! Oh shoot, doc haywire is still ongoing. Asking for related docs is a bad idea.
sunny-green
sunny-green•7mo ago
not sure if we have docs about that explicitly . there are a few APIs that make more sense with loaderdata e.g. head()
vicious-gold
vicious-goldOP•7mo ago
I'm gonna look up for head() and tinker with it, thanks again! Default preloadStaleTime is 30secs but default staleTime is 0. So even I preloaded data for a route when I move to the route within 30 secs loader is called again. What's the meaning of this?
sunny-green
sunny-green•7mo ago
meaning is that you will be able to instantly show the data but the data might be stale so it fetches it again in the background and updates if it changed
vicious-gold
vicious-goldOP•7mo ago
Ahhh So when I move to the route, it shows preloaded data anyway and then run loader to fetch the latest data, shrewd!
sunny-green
sunny-green•7mo ago
yes
vicious-gold
vicious-goldOP•7mo ago
@Manuel Schiller Thanks to you, I have finally finished my TSR 101 tutorial.🎉
sunny-green
sunny-green•7mo ago
what does that mean? you created a tutorial?
vicious-gold
vicious-goldOP•7mo ago
Yes, it's in Japanese though. Now I can sell TSR hard here in Japan.

Did you find this page helpful?