2017-06-20 72 views
0

我有嵌套如使用帶開關如下反應路由器4如何使用React Router 4將開關傳遞給this.props.children?

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

在主成分頁我有一些狀態,我想通過作爲道具this.props.children。 在主要組件渲染方法中,我寫了{this.props.children}來訪問子組件。現在,如何通過我的CustomProps到this.props.children

在此先感謝幫助

+0

這裏是你的問題https://stackoverflow.com/questions/32370994/how-to-pass-props-to-this-props答案讓你的狀態 - 兒童 –

回答

0

假設你的狀態是一天:monday.then你需要通過在孩子狀態

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

<MainComponent> 

而在你的子組件ChildComponent您可以使用

this.props.day 
+0

,但在我的渲染方法的主要組件我傳遞{this.props.children}所以我想知道如何傳遞自定義道具{this.props.children}使用ES6中的反應路由器4 –

+0

看看這個答案https://stackoverflow.com/questions/43796916/router-match-is-not-been-called-on-every-route-change/43797059#43797059 –

相關問題