我无法渲染 nextjs
I can't render nextjs
我正在处理一个 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}/>
})
}
组件未呈现。
您必须 return 使用 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}
/>
)
}
}
我正在处理一个 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}/>
})
}
组件未呈现。
您必须 return 使用 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}
/>
)
}
}