I am having nesting as follows with switch using react router 4
<MainComponent>
<ChildComponent></ChildComponent>
<ChildComponent></ChildComponent>
<ChildComponent></ChildComponent>
<MainComponent>
On main component page i am having some state which i want to pass as props to this.props.children. In Main component render method i had written {this.props.children} to access children component. Now how to pass my CustomProps to this.props.children
Thanks in Advance for help
Suppose your state is day:monday.then you need to pass the state in child as
<MainComponent>
<ChildComponent day={this.state.day}/>
<MainComponent>
And in your child component ChildComponent you can get your state using
this.props.day
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.