我无法渲染nextjs

时间:2020-06-03 18:42:24

标签: next.js repl.it

我正在研究nextjs项目,并且在通过jsx分发元素时遇到问题。这是我的代码:

{
        this.state.projects.forEach((projects)=>{
          <Project name={projects.name} id={projects.id} url={`/projects/${projects.id}`} description={projects.description} ownerUsername={projects.author.username} ownerImage={projects.author.image}/>
        })
}

该组件无法渲染。

1 个答案:

答案 0 :(得分:0)

您必须使用Array.prototype.map

为您的用例返回一个数组
{
   this.state.projects.map((project)=> {
         return (<Project
                   key={project.id} // don't forget the key prop
                   name={project.name} 
                   id={project.id} 
                   url={`/projects/${project.id}`} 
                   description={project.description} 
                   ownerUsername={project.author.username} 
                   ownerImage={project.author.image}
                 />
            )
  }
}