<script type="text/babel">
var data = [
{id: 1, author: "Qamar", text: "This is one comment"},
{id: 2, author: "Aftab", text: "This is *another* comment"}
];
var CommentList = React.createClass({
render: function() {
var commentNodes = this.props.data.map(function(comment) {
return (
<Comment author={comment.author} key={comment.id}>
{comment.text}
</Comment>
);
});
return (
<div className="commentList">
{commentNodes}
</div>
);
}
});
ReactDOM.render(,的document.getElementById(&#39;例如&#39;));
这个例子出了什么问题..当在评论列表中添加{customNodes}时,这就是崩溃。
答案 0 :(得分:1)
正如我在您的示例中看到的,virtual
组件
Comment
也要var Comment = React.createClass({
render: function() {
return <div>
<p>{ this.props.children }</p>
<p>{ this.props.author }</p>
</div>;
}
});
你应该将React Component作为第一个参数传递
ReactDOM.render