考虑这个无法编译的例子:
/** @jsx React.DOM */
var Hello = React.createClass({
render: function() {
return <div>Hello</div>;
}
});
var World = React.createClass({
render: function() {
return <div>World</div>;
}
});
var Main = React.createClass({
render: function() {
return (
<Hello />
<World />
);
}
});
React.renderComponent(<Main />, document.body);
但这些组合中的任何一个都可以工作:
<div>
<Hello />
<World />
</div>
<Hello />
//<World />
//<Hello />
<World />
想知道多个组件是否应该始终被 div 标签包围。
我认为渲染函数应该只返回一个组件。
来自文档:http://facebook.github.io/react/docs/component-specs.html http://facebook.github.io/react/docs/component-specs.html
render() 方法是必需的。
调用时,它应该检查 this.props 和 this.state 并返回单个子组件
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)