I\'m trying to find the proper way to define some components which could be used in a generic way:
I needed to fix accepted answer above to make it work using that instead of this pointer. This within the scope of map function didn't have doSomething function defined.
var Parent = React.createClass({
doSomething: function() {
console.log('doSomething!');
},
render: function() {
var that = this;
var childrenWithProps = React.Children.map(this.props.children, function(child) {
return React.cloneElement(child, { doSomething: that.doSomething });
});
return {childrenWithProps}
}})
Update: this fix is for ECMAScript 5, in ES6 there is no need in var that=this