0

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

Vinit S
  • 69
  • 3

1 Answers1

0

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
Vikram Saini
  • 2,713
  • 1
  • 16
  • 33
  • but in my main component in render method i am passing {this.props.children} so i want to know how to pass custom props to {this.props.children} using React Router 4 in ES6 – Vinit S Jun 20 '17 at 10:12
  • have a look at this answer https://stackoverflow.com/questions/43796916/router-match-is-not-been-called-on-every-route-change/43797059#43797059 – Vikram Saini Jun 20 '17 at 10:15