export const ProductDetail = () => {
const { data, isFetching } = trpc.productDetail.useQuery({ id: "1234" })
if (isFetching || !data) return
Loading...
return (
Product name: {data.name}
)
}
Browser JS
Node.js
const getContext = () => ({ prisma })
const { router, procedure } = initTRPC.context().create()
const productDetail = procedure
.input(z.object({ id: z.string() }))
.query(async ({ ctx: { prisma }, input: { id } }) => {
const result = await prisma.product.findUnique({ where: { id } })
return {
id: result.id,
name: result.name,
price: result.price,
}
})
export const appRouter = router({
productDetail,
})
export type AppRouter = typeof appRouter
Internet
Inference Inference