Can i use a single trpc proxy client in NextJS 12?
Hey guys quick question if anyone is around. Are there any issues with defining a trpc proxy client once in nextjs pages router and then reusing it in client components by manually passing it to a useQuery?
Unfortunately our backend team has created multiple trpc routers and we still haven't upgraded from react-router v3, so the trpc-react-query integration isn't a high priority for us, but will there be any caching or request sharing issues when using a single trpc proxy client?
2 Replies
If youre using pages router still (I think you are in v12), as long as you have a single
<QueryClientProvider />
wrapping your app, you are fine to use a single trpc instance. Heres an example I have:
https://github.com/tylerpashigian/t3-recipe-book/blob/main/src/utils/api.ts#L21
I am using createTRPCNext()
instead of createTRPCProxyClient()
, but looks similar enough.I checked your code and yeah we create a query client once in _app.page.tsx. Thank you for your reply 🙏