As a newcomer to Nextjs, I am currently working on a blog project utilizing the T3 Stack (Nextjs, Typescript, Prisma, tRPC). I have encountered an error while attempting to fetch post content by ID. Below are the relevant sections of my code. Any assistance would be greatly appreciated :)
This is the router snippet:
getPost: publicProcedure
.input(
z.object({
postId: z.string(),
})
)
.query(({ ctx, input }) => {
const { postId } = input;
return ctx.prisma.post.findUnique({
where: { id: postId },
include: { Category: true, author: true },
});
}),
And here's the postview component section:
export const PostView: FC<PostViewProps> = ({ id }) => {
const { data } = api.posts.getPost.useQuery({ postId: id });
return (
<Container maxWidth="xl">
<Box>
<Image src={"/logo.png"} alt="logo" width={180} height={180} />
</Box>
<Typography variant="h4">{data?.title}</Typography>
<Typography>{data?.content}</Typography>
</Container>
);
};
I have tried various solutions found online and consulted chatgpt, but unfortunately, I am still facing the same error.