Nextjs中的“TypeError:getStaticPaths is not a function”错误

piv4azn7  于 2023-08-04  发布在  其他
关注(0)|答案(1)|浏览(313)

首先,我是Nextjs的新手,使用T3 Stack(Nextjs,Typescript,Prisma,tRPC)制作博客项目。当我想用id拉取文章内容时,我得到了这样的错误。我也会添加我的代码。我很高兴有人能帮上忙:)
这是我的路由器:

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 },
      });
    }),

字符串
这是我的postview组件:

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>
  );
};


我在网上和chatgpt上尝试了很多解决方法,但都无法通过错误。

5rgfhyps

5rgfhyps1#

可能还有更多,但下面会立即进行修正。您需要将处理程序函数asyncawait设置为prisma查询。

getPost: publicProcedure
    .input(
      z.object({
        postId: z.string(),
      })
    )
    .query(async ({ ctx, input }) => {
      const { postId } = input;
      return await ctx.prisma.post.findUnique({
        where: { id: postId },
        include: { Category: true, author: true },
      });
    }),

字符串

相关问题