[英]Is there any required div wrapper inside a React component
I create a menu using React JS: 我使用React JS创建菜单:
var Dropdown = React.createClass({
render: function() {
return (
<Title />
<OptionsDropdown />
);
}
});
where Title and OptionsDropdown are other React classes. 其中Title和OptionsDropdown是其他React类。 The problem is this code has error until I wrap them around a div like :
问题是这段代码有错误,直到我将它们环绕在div周围,例如:
var Dropdown = React.createClass({
render: function() {
return (
<div class="something">
<Title />
<OptionsDropdown />
</div>
);
}
});
Is there anyway better to handle this situation when I want no div is wrapped outside Title and OptionsDropdown. 当我不希望在Title和OptionsDropdown外包裹任何div时,还有什么更好的方法来处理这种情况?
Finally. 最后。 I found out there is maximum one root node in render function in React JS.
我发现React JS的render函数中最多有一个根节点。 Better to wrap it with a div.
最好用div包裹它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.