小编Ade*_*ect的帖子

错误:如何从 getStaticProps 序列化数据:Next.js

我正在使用 Next.js,我尝试访问数据但出现此错误:

Error: Error serializing `.profileData` returned from `getStaticProps` in "/profile/[slug]".
Reason: `undefined` cannot be serialized as JSON. Please use `null` or omit this value.
Run Code Online (Sandbox Code Playgroud)

我的代码:

import { getAllBusinessProfiles } from '../../lib/api';

const Profile = ({ allProfiles: { edges } }) => {
    return ( 
        <>
          <Head>
            <title>Profile</title>
          </Head>

          <Hero />

          <section>
            {edges.map(({ node }) => (
              <div key={node.id}>
                  <Link href={`/profile/${node.slug}`}>
                    <a> {node.businessInfo.name} </a>
                  </Link>
              </div>
            ))}
          </section>

        </>
     );
}
 
export default Profile;

export async function getStaticProps() {
    const …
Run Code Online (Sandbox Code Playgroud)

javascript ecmascript-6 reactjs next.js

8
推荐指数
3
解决办法
5416
查看次数

标签 统计

ecmascript-6 ×1

javascript ×1

next.js ×1

reactjs ×1