[英]Returned component in react not defined
I apologize because I'm sure this has been answered somewhere before but for the life of me I can't find it. 我很抱歉,因为我确定这已经在之前的某个地方得到了解答,但是对于我的一生,我找不到它。 I'm trying to make a simple comment box using react and I keep getting the error:
我正在尝试使用react创建一个简单的注释框,但不断出现错误:
./src/CommentBox.js Line 29: 'Comment' is not defined react/jsx-no-undef ./src/CommentBox.js第29行:未定义“评论” react / jsx-no-undef
I read online that needs to be uppercase. 我在网上阅读的内容必须大写。 I've tried it lower case and my page loads without error but / is missing.
我尝试使用小写字母,并且页面加载没有错误,但是/丢失了。 Sorry if i'm using the wrong terms.
抱歉,如果我使用了错误的条款。 I'm new at this.
我是新来的。
Thanks! 谢谢!
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`
}
}
}
您还没有创建任何组件评论
You named your React Component CommentBox
, not Comment
. 您将自己的React Component命名为
CommentBox
,而不是Comment
。 Replace Comment
with proper Component name. 用正确的组件名称替换
Comment
。
导入评论组件。
import Comment from 'Comment component file name';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.