简体   繁体   English

Map function 不渲染元素

[英]Map function doesn't render elements

Im starting with Next.js and I'm trying to render some data from CMS.我从 Next.js 开始,我正在尝试从 CMS 呈现一些数据。 I can access data inside map function, but I cant render any element inside it.我可以访问 map function 中的数据,但我无法在其中呈现任何元素。 Here is my index.tsx这是我的 index.tsx

type OpenJobsProps = {
    slug: string,
    image: string
}

const JoinUs = ({ jobs }: InferGetStaticPropsType<typeof getStaticProps>) => {
    return(
        <Layout>
            <Welcome>
                <h1>Join us</h1>
                <p>It’s designed to appeal to emotions, in order to<br/> achieve rational goals. The concept doesn’t make<br /> logical sense at first.</p>
            </Welcome>
            <OpenJobs>
                {jobs.data.map((item: any, index: number) => {
                    {console.log(item)}
                    <>
                        <OpenJobItem slug={item.slug} source={item.image}/> 
                        <p>{item.slug}</p>
                    </>
                })}
            </OpenJobs>
            <Culture/>
        </Layout>
    )
}

export const getStaticProps: GetStaticProps = async (ctx) => {
    const jobs: OpenJobsProps[] = (await getAllOpenJobs() || [])

    return {
      props: {
        jobs,
      }
    }
  }

export default JoinUs;

console log returns控制台日志返回在此处输入图像描述 But map function doesnt return any element or component.但是 map function 不返回任何元素或组件。

add return添加return

{jobs.data.map((item: any, index: number) => {
    console.log(item);
    return (<>
        <OpenJobItem slug={item.slug} source={item.image}/> 
        <p>{item.slug}</p>
    </>);
})}

or just:要不就:

{
    jobs.data.map((item: any, index: number) => (<>
        <OpenJobItem slug={item.slug} source={item.image} />
        <p>{item.slug}</p>
    </>))
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM