wleistra
shared useTRPCClient hook conversion to v11
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
14 replies
tRPC querying data via function not working
The error is pretty self explanatory. You are calling a hook somewhere that is not a hook or component. I cannot see from your code example what the problem is but if you have your code snippet running in a function try rename it as useFetchSocialData or make sure the code is ran as part of the top level of a component. You can also not call a hook conditionally (inside an if) so keep that in mind as well. Also your fetch functions should be probably inside the useEffects or using a useCallback if they are called from other places and your useEffects currently have missing dependencies on the dependency array. They are now recreated on every rerender.
3 replies
Multiple Inputs on TRPC Procedure?
Define your input as a an object of which one key is the cart array and the second key in the object is the user details. Something along the lines of procedure.input(z.object({cart: [], user: {...}) if you use zod. If you want to give a possible user object on every call you probably want to have a look at trpc middleware and the context.
2 replies
Axios, ExpressMiddleware and TRPCErrors
I found a solution. The cause key on the error object was my Axios error, and after an isAxiosError check, it can be cast as such, and there I get the actual response from my Axios query. So now I could use the errorFormatter on context creation to return those codes to the client instead of the previous 500/INTERNAL_SERVER_ERROR generic error seen there.
6 replies
Axios, ExpressMiddleware and TRPCErrors
The issue I'm having is that I cannot access the error response from axios in OnError or ErrorFormatter to base any robust logic to throw the trpcError with unauthorized code. What I would like to avoid is rely on the error message and do some kind of if string of message includes 401... So I was hoping there would be another way or some way to work with the error (httpStatus) from Axios that TRPC receives.
6 replies