私はリアクタを初めて使用していますが、私はそれについてどう考えているのか分かりません。ここでは、コンポーネントをネストされたルートでロードしています。リアクタとthis.props.children - どのようにthis.props.childrenに状態を渡すか
エントリポイントが
ReactDOM.render(
<Router history={hashHistory} >
<Route path="/" component={App}>
<Route path="models" component={Content}>
</Route>
</Router>,
document.getElementById('app')
);
App.js
render: function() {
return (
<div>
<Header />
{this.props.children}
</div>
);
}
だから、私のアプリの子供は私がフラックスを使用して、私のしています。中に送信されたコンテンツ構成要素であるが.jsファイルApp.jsには状態があり、変更をリッスンしますが、この状態をthis.props.childrenに渡す方法はわかりません。反応ルータを使用する前に、私のApp.jsはすべての子を明示的に定義しているので、状態を渡すことは自然でしたが、今はそれをどうやって行うのか分かりません。あなたはその後、あなたの子コンポーネントは、小道具、this.props.foo
を経由して、これをアクセスすることができますthis.props.children
render: function() {
var children = React.Children.map(this.props.children, function (child) {
return React.cloneElement(child, {
foo: this.state.foo
})
})
return <div>{children}</div>
}
の状態、小道具や他のものは何でもを追加することができますリアクトヘルパーメソッドのカップルを使用して
の可能性のある重複[{this.props.children}に小道具を渡す方法](http://stackoverflow.com/questions/32370994/how-to-pass-props-to-this-props-子供) –