2017-06-20 11 views
0

私はthis.props.childrenする小道具として渡したいいくつかの状態が生じていますルータ主成分ページ4React Router 4とスイッチを使ってthis.props.childrenに小道具を渡すには?

<MainComponent> 
    <ChildComponent></ChildComponent> 
    <ChildComponent></ChildComponent> 
    <ChildComponent></ChildComponent> 
<MainComponent> 

を反応させ使用して、スイッチで次のように入れ子に持っています。 メインコンポーネントのレンダリングメソッドでは、子コンポーネントにアクセスするために{this.props.children}を記述しました。今、あなたの状態が一日であると仮定し、ヘルプ

+0

を使用して、あなたの状態を取得することができますChildComponentコンポーネントは、あなたの質問に対する答えはhttps://stackoverflow.com/questions/32370994/how-to-pass-props-to-this-propsです - 子供 –

答えて

0

のため事前に

感謝をthis.props.childrenために私CustomPropsを渡す方法:あなたは

<MainComponent> 
    <ChildComponent day={this.state.day}/> 

<MainComponent> 

として、子供の状態を渡す必要がありmonday.thenそして、あなたの子供にあなたがここ

this.props.day 
+0

しかし、レンダリングメソッドの私の主なコンポーネントでは、私は{this.props.children}を渡しているので、私はES6でReact Router 4を使ってカスタムプロップを{this.props.children}に渡す方法を知りたいです –

+0

この回答を見てくださいhttps://stackoverflow.com/questions/43796916/router-match-is-not-been-called-on-every-route-change/43797059#43797059 –

関連する問題