T
tRPC

❓-help

Can you ensureData without the useUtils hook?

SScythern1/17/2024
The Tanstack Router docs recommend calling ensureQueryData in a route’s loader function if using Tanstack Query: https://tanstack.com/router/v1/docs/guide/external-data-loading#a-more-realistic-example-using-tanstack-query As far as I can tell, ensureQueryData is only available through the trpc useUtils hook in a component. Can I get it, or the full query options, some other way?
Solution:
I had the same problem so in v11 there's createQueryUtils which allows you to do it without the hook
Jump to solution
External Data Loading | TanStack Router Docs
⚠️ This guide is geared towards external state management libraries and their integration with TanStack Router for data fetching, ssr, hydration/dehydration and streaming. If you haven't read the standard Data Loading guide To Store or to Coordinate?
Solution
SSebasPtsch1/17/2024
I had the same problem so in v11 there's createQueryUtils which allows you to do it without the hook
SScythern1/17/2024
Thanks - is it createTRPCQueryUtils?
SSebasPtsch1/17/2024
Yes

Looking for more? Join the community!