我试图在部分功能组件中显示基于类的组件的内容,但它不起作用。基于类的组件:
class commentForm extends Component {
render() {
return(
<div>
<h1>Hello</h1>
<Button class="btn btn-light"><span className="fa fa-comment-o"></span> Submit
comment</Button>
</div>
);
}
}
功能组件:
function RenderComments({comments})
{
if(comments!=null)
{
return (
<div className="col-12 col-md-5 m-1">
<h4>Comments</h4>
<ul className="list-unstyled">
{comments.map((comment)=>{
return(
<li key={comment.id}>
<p>{comment.comment}</p>
<p>-- {comment.author} , {new Intl.DateTimeFormat('en-US',{ year: 'numeric', month: 'short', day:'2-digit' }).format(new Date(Date.parse(comment.date)))}</p>
</li>
);
})}
</ul>
<commentForm />
{commentForm}
</div>
)
}
else{
return(
<div></div>
);
}
}
.
这里我想显示来自 RenderComments 的 commentForm 的内容。我没有收到任何错误,但代码未在前端显示 commentForm 的内容。