1

Hi all and thanks for your time.

I see a tutorial with lynda.com for React.js. But, it used a old version of React. His code:

render: function(){
    return (
    <div>
        <Header title={this.state.title} status={this.state.status}/>
        <RouteHandler {...this.state} />
    </div>
    )
}

But i use a new version of React 15.2.1 and React-router 2.5.2. And i don't know how pass {...this.state} with {this.props.children}

render: function(){ 
    return (
    <div>
        <Header title={this.state.title} status={this.state.status}/>
        {this.props.children} 
    </div>
    )
}

Thank you, everyone

Kokovin Vladislav
  • 10,241
  • 5
  • 38
  • 36
Rifton007
  • 291
  • 1
  • 5
  • 24
  • Possible duplicate of [React router and this.props.children - how to pass state to this.props.children](http://stackoverflow.com/questions/35835670/react-router-and-this-props-children-how-to-pass-state-to-this-props-children) – azium Jul 15 '16 at 19:27
  • Can u post a link containing your code in JSFddle or codepen. Its hard to understand from above example. – Galeel Bhasha Jul 15 '16 at 23:00

2 Answers2

2

in order to pass some props to {this.props.children}, you can use React.cloneElement.The resulting element will have the original element's props with the new props merged in shallowly.

render: function(){ 
    return (
    <div>
        <Header title={this.state.title} status={this.state.status}/>
        {React.cloneElement(this.props.children,this.state)} 
    </div>
    )
}
Kokovin Vladislav
  • 10,241
  • 5
  • 38
  • 36
-1

It's me again, i have to add an emit In tutorial, with old version of React.

<RouteHandler **emit={this.emit}** {...this.state}/>

Now, how to add emit ?

{React.cloneElement(this.props.children, this.state)} //where add emit ?

Thanks,

Rifton007
  • 291
  • 1
  • 5
  • 24