Custom Hooks using tRPC API
I want to create a custom hook with the function I created in tRPC routes.
getUserDetails: privateProcedure.query(async ({ c, ctx }) => {
const user = await db.user.findFirst({
where: {
email: ctx.user.email,
},
});
if (!user) {
return c.json({
message: "User not found",
success: false,
data: null,
code: NOT_FOUND,
});
}
return c.json({
message: "User found",
success: true,
data: user,
code: OK,
});
}),
i want to create use-user.ts custom hook but I dont know how to use tRPC API, I'm using tRPC v11. Can someone help me on this.
3 Replies
TanStack React Query | tRPC
TanStack React Query setup
Hi @Vishnu Mouli, what lib are you using with trpc that you doing
c.json(...
?Sorry that was hono js, earlier i was using jstack and shifted to trpc