我正在研究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}/>
})
}
该组件无法渲染。
答案 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}
/>
)
}
}