ChenC
tRPC2y ago
4 replies
Chen

Can you ensureData without the useUtils hook?

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?
⚠️ 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
I had the same problem so in v11 there's createQueryUtils which allows you to do it without the hook
Was this page helpful?