正在关注他们网站上的 ReactJS 教程。
var Comment = React.createClass({
render: function() {
return (
<div className="comment">
<h2 className="commentAuthor">
{this.props.author}
</h2>
{this.props.children}
</div>
);
}
});
var CommentList = React.createClass({
render: () => {
return (
<div className="commentList">
<Comment author="Pete Hunt">This is one comment</Comment>
<Comment author="Jordan Walke"> This is *another* comment</Comment>
</div>
);
}
});
var CommentForm = React.createClass({
render: () => {
return (
<div className="commentForm">
Comment Form
</div>
);
}
});
var CommentBox = React.createClass({
render: () => {
return (
<div className="commentBox">
<h1>Comments</h1>
<CommentList />
<CommentForm/>
</div>
);
}
});
ReactDOM.render(
<CommentBox />,
document.getElementById("content")
);
但是,如果我在第一个组件注释中使用箭头符号,即:
(*参数*) => {}
而不是普通的函数声明符号,即:
函数(*参数*){}
chrome解释器会吐出以下错误:
未捕获的类型错误:无法读取未定义的属性“道具”
任何人都可以对此事有所了解吗?