1
我想在另一个组件使用的部件,像这样的反应...React.js如何在另一个组件中使用组件?
var ContentBox = React.createClass({
render: function() {
return (
<div>
<div className="container-fluid">
<div className="box center-block">
{this.props.children}
</div>
</div>
</div>
);
}
});
var Quotesection = React.createClass({
render:function() {
return(
<ContentBox><h1 className="text-center">Example text</h1></ContentBox>
);
}
});
ReactDOM.render(<ContentBox/>, document.getElementById('app'));
但我得到的是盒子,而不是盒子,盒子里面的报价。如果任何人都可以提供帮助,那会很棒。
感谢那些工作,我不知道为什么它做虽然这种方式。所以,如果我想添加另一个组件,我不得不在ReactDOM.render中调用这个新创建的组件,所以它有点像它的组合。如果我想要使用多个组件,我正在做的方式是正确的吗? – CodePanda
是的。通常你会有一个由其他组件组成的高级组件。没有什么比一个网页通常用纯html构建。 – Chris