我有一个NextJS和Sanity.io博客项目。今天我更新了NextJS从13.2.3到13.4.2,当我尝试运行它时,我得到了这个错误:
错误:(0,next_headers__WEBPACK_IMPORTED_MODULE_1__.previewData)不是函数
代码如下:
import { previewData } from "next/headers";
import { groq } from "next-sanity";
import { client } from "../../lib/sanity.client";
import PreviewSuspense from "../../components/PreviewSuspense";
import BlogList from "../../components/BlogList";
import PreviewBlogList from "../../components/PreviewBlogList";
const query = groq`
*[_type == "post"] {
...,
author->,
categories[]->
} | order(_createdAt desc)
`;
//export const revalidate = 60; // revalidate this page every 60 seconds
export default async function HomePage() {
if (previewData()) {
return (
<PreviewSuspense
fallback={
<div role="status">
<p className="text-center text-lg animate-pulse text-[#F7AB0A]">
Loading Preview Data...
</p>
</div>
}
>
<PreviewBlogList query={query} />
</PreviewSuspense>
);
}
const posts = await client.fetch(query);
return <BlogList posts={posts} />;
}
我该怎么解决这个问题?我必须用别的东西吗?
1条答案
按热度按时间ws51t4hk1#
在我的例子中,我这样实现
单位:
app/api/draft/route.ts
单位:
app/api/exit-draft/route.ts
单位:
page.tsx