trpc.useQuery() succeeding but returning empty data?

Ive checked my db and the entries definitely exist. and the query is sending the right Id input to find a unique entry using the id. But the data object in the useQuery result is undefined
3 Replies
asheeshh
asheeshh3y ago
pls always send your code with questions like these
Donny D
Donny DOP3y ago
/** In the router **/
.query('getById', {
input: z.object({
id: z.number()
}),
resolve: asynd ({ input, ctx }) => {
await ctx.prisma.story.findUnique({
where: {
id: input.id
}
})
}
})
/** In the router **/
.query('getById', {
input: z.object({
id: z.number()
}),
resolve: asynd ({ input, ctx }) => {
await ctx.prisma.story.findUnique({
where: {
id: input.id
}
})
}
})
and in the component calling it
const router = useRouter();
const { storyId } = router.query;
const { data: story } = trpc.useQuery(['story.getById', { id: Number(storyId)] }]);
const router = useRouter();
const { storyId } = router.query;
const { data: story } = trpc.useQuery(['story.getById', { id: Number(storyId)] }]);
....................lmao I forgot the word return, that's the problem Thanks for the rubber ducking
asheeshh
asheeshh3y ago
lol
Want results from more Discord servers?
Add your server