未验证 提交 e404b996 编写于 作者: A Ante Sepic 提交者: GitHub

[Examples] Prevent getStaticProps from returning "undefined" (#19012)

If the example is cloned and ran with no further setup (no environment variables set up), it will error out because `extractPostEntries` will return `undefined` which can not be serialized by `getStaticProps `.

This PR basically ensures that we return an empty array instead of the `undefined` for a collection of posts, and a `null` instead of the `undefined` for a single post.
上级 f300ecaa
......@@ -36,7 +36,7 @@ export default function Index({ preview, allPosts }) {
}
export async function getStaticProps({ preview = false }) {
const allPosts = await getAllPostsForHome(preview)
const allPosts = (await getAllPostsForHome(preview)) ?? []
return {
props: { preview, allPosts },
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册