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