[英]Returned component in react not defined
我很抱歉,因为我确定这已经在之前的某个地方得到了解答,但是对于我的一生,我找不到它。 我正在尝试使用react创建一个简单的注释框,但不断出现错误:
./src/CommentBox.js第29行:未定义“评论” react / jsx-no-undef
我在网上阅读的内容必须大写。 我尝试使用小写字母,并且页面加载没有错误,但是/丢失了。 抱歉,如果我使用了错误的条款。 我是新来的。
谢谢!
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
class CommentBox extends React.Component {
render () {
const comment = this._getComments();
const commentCount = `{comment.length}`;
return (
<div className = "comment-box">
<h3>COMMENTS</h3>
<h4 className = "commentCount">
{this._getCommentsTitle(comment.length)} </h4>
<div className = "comments">
{comment}
</div>
</div>
);
}
_getComments(){
const commentList = [
{id: 1, author: 'Michael Perez', body: 'Awesome Pictures!'},
{id: 2, author: 'Tofu Kaplan', body: 'Looks like fun but happy you
are home :)'}
];
return commentList.map((comment) => {
return(
< Comment
author = {comment.author} body = {comment.body} key =
{comment.id} />
)
});
}
_getCommentsTitle(commentCount){
if (commentCount === 1){
return "1 comment";
} else {
return `${commentCount} comments`
}
}
}
您还没有创建任何组件评论
您将自己的React Component命名为CommentBox
,而不是Comment
。 用正确的组件名称替换Comment
。
导入评论组件。
import Comment from 'Comment component file name';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.