Tanstack Router loader integration question
Could someone explain why ensureData is used in the loader but useQuery is used in the component in this example?
https://github.com/TanStack/router/blob/main/examples/react/with-trpc-react-query/app/routes/dashboard.posts.%24postId.tsx
Thank you
GitHub
router/examples/react/with-trpc-react-query/app/routes/dashboard.po...
🤖 Fully typesafe Router for React (and friends) w/ built-in caching, 1st class search-param APIs, client-side cache integration and isomorphic rendering. - TanStack/router
4 Replies
conscious-sapphire•12mo ago
one fills the cache, the other creates a subscriber that reads from the cache
jolly-crimsonOP•12mo ago
@TkDodo 🔮 what would the downside of using useQuery in both places be?
Actually, I was searching this more and found a blog post you wrote about query + react router that cleared this up for me 🙂
conscious-sapphire•12mo ago
you can't call a hook (useQuery) in a route loader. rules of hooks and all...
jolly-crimsonOP•12mo ago
Right, I was a bit shaky on imperative fetching and when/why put I understand now