shared useTRPCClient hook conversion to v11
In our mono repo, we have 30 or so MFEs which all use the same TRPC client setup. So, we abstracted the inner workings of getting the TRPC client set up away in a different package as a hook. Now, I'm converting the code to v11, and I'm running into deprecation warnings and typescript errors. Our hook looks like this:
Issue 1: TRPCClient type is no longer exported from @trpc/client. I assume we can replace it with
createClient: (opts: { links: TRPCLink<TRouter>[] }) => ReturnType<typeof createTRPCClient>;
correct?
Issue 2: the AnyRouter type deprecation, how can that be resolved?6 Replies
Why not use
@trpc/react
?We do! The prop trpc is coming from createReactRouter<AppRouter> like this
And this is how we put it all together
If there is a more efficient/better practice to achieve the sharing of the same client setup across all our Frontends without duplicating the code I'm all ears too... So far we successfully used this way with trpc 10
there should be comments on all deprecations
feel free to make a pr on things that we might've removed
we have started being explicit about what we import + added smurfing(https://blog.codinghorror.com/new-programming-jargon/#21) on most variables/types
if you need consulting for the migration email you can email sales@trpc.io
This is the information vscode gives about the deprecation:
Maybe a comment was missed along the way?
When trying to use Router<any, any> directly it says Router is not exported from @trpc/server
I worked around the issue by not returning the createClient but by returning the links instead. and have the createClient in the MFE's own useState.
Thanks @Alex / KATT š± for the extra details on the comments.