T
TanStack14mo ago
absent-sapphire

tRPC in context or constant?

I'm looking at the tRPC + React Query example, and I'm confused on whether to pass the tRPC variable to the context. I see that it is defined that way but when each component access the tRPC var it uses it from the global scope instead of the one in the context, is that by design? Or is it just because it's in the same file, and it should be accessed from the context?
1 Reply
vicious-gold
vicious-gold14mo ago
In the trpc + react-query example, when it's being used in the component, it's just using the one from the global context. This is because this is how you get access to the typed trpc hooks. From what's passed into the context in the example, it's the trpcUtios which are primarily used.

Did you find this page helpful?