trpc hook pattern. This works, but I’m not convinced…

I want to call my route when a button is clicked and have access to isLoading, onError etc… I have implemented a pattern using ‘’refetch()’’ but it doesn’t feel ‘correct’ is there a better way of doing this. I will also create a custom hook out of it. ‘’’js const { refetch } = trpc.authDomain.signIn.useQuery( { email: userEmail }, { enabled: false, onError: (e: any) => { console.log('there was an error with the endpoint'); }, } ); async function isEmailVerified() { const response = await refetch(); const verification =; // i want to access isLoading directly without writing many lines of new code which i would have to with this current approach if (verification?.status === 'tryAgain') { console.log('email not verified'); setHasInitiatedSignIn(true); } if (verification?.status === 'ok') { console.log('user can now verify code sent to their email address'); setHasInitiatedSignIn(true); } } Return <button onClick={isEmailVerified}/> ‘’’
Unknown User497d ago
A Dan497d ago
there are no implementation differences between query and mutation according to the docs, its just semantics. Also by definition it’s a query, because its checking if the database exists in the database only. I think i was wrong on this part, and you are right.
isaac_way491d ago
@Ayo even though there is no difference in mutation/query in trpc, thereis a big difference between mutations and query in react query which is what you’re using here
A Dan490d ago
Thank you! This helped my understanding
More Posts
Catch TRPCError, ZoddError on the front-endi am throwing a TRPCError in a mutation. i dont understand how to catch this error in the OnError meimplicitly has type 'any' because it does not have a type annotation and is referenced directlyRunning into this error. I feel like it's some sort of infinite recursion issue, but not sure where Why do some examples create PrismaClient in context, and others don’tIs there a specific reason to do this or not to do this? I can imagine with the new Prisma extensionAppRouter type any?I am trying to use trpc in a Turbo repo and when I export the AppRouter on the server side it is as an inputHi, I have ```ts, z.string()) ``` as an input, but when I try to pass the map as correct way to call TRPC inside a functioni want a user to be able to sign after they have a clicked a button but i get a hooks error. can anyCannot find namespace 'trpc'I'm getting this error when trying to access <trpc.Provider ...>. Any idea what might be going on?use tRPC for RPC calls instead of gRPCHi, I know that tRPC and gRPC are different things - despite the similar name. Nevertheless I woutRPC caching vs Vercel dynamic edge cachingWhat is the difference, or improvements, on Vercel's dynamic edge caching? tRPC server caching worksIgnore Errors from batch callsI have some of my routers throw helpful errors for the client to use in the error message object, buAny way to view headers in middleware?Middleware `input` doesn't seem to have it :/How can I use a fork of trpc-next?Hey there, I've made a fork of @trpc in order to fix an issue inside of @trpc/next. I can build it atrying to cache api routesHello. I am using TRPC to make a site which integrates with a third party API. I need to add cachinPrisma+TRPC monorepoHey, so we have a monorepo with 3 backend services and 3 frontend services. It looks like the follow