当我运行“下一次导出”时,我收到以下错误。我的构建很好,但导出失败。我一直在关注很多教程,但找不到解决方案。我是否正确定义了我的someEntryAsProp
?
import Layout from '../components/myLayout.js'
import Link from 'next/link'
import {createClient} from '../helpers/getcontent';
import { type } from 'os';
function getPosts(){
return [
{ id:'hello-nextjs' , title:'Hello Next.js' },
{ id:'learn-nextjs' , title:'Learn Next.js is awesome' },
{ id:'deploy-nextjs' , title:'Deploy apps with Zeit' },
]
}
const PostLink = ({ post }) => (
<li>
<Link as={`/p/${post.id}`} href={`/post?title=${post.title}`}>
<a>{post.title}</a>
</Link>
</li>
)
const Index = () => (
<Layout>
<h1>My Blog</h1>
<p>{someEntryAsProp.fields.title}</p>
<ul>
{ getPosts().map((post) => (
<PostLink key={post.id} post={post}/>
))}
</ul>
</Layout>
);
Index.getInitialProps = async () => {
console.log('> Starting import',);
const client = createClient();
const entries = await client.getEntries({
// some query
content_type:type,
include:2
})
console.log(entries.items[0])
console.log('> Content gotten and written for',)
return { someEntryAsProp: entries.items[0] };
//return {};
};
export default Index
错误:
TypeError:无法读取未定义的属性'someEntryAsProp'
任何人都可以帮助我,我做错了吗?
您需要将props作为参数传递给页面组件:
const Index = ({someEntryAsProp}) => (...)