代码如图,我在程序中使用antd的layout组件来布局,同时this.props中有一个globaluser属性,请问如何在Content中的this.props.children中获取到globaluser呢?
React传值问题求助
wupingzsf
#1
benzeph
#4
const Child = React.createClass({
render: function() {
return <div onClick={() => this.props.doSomething(this.props.value)}>Click Me</div>;
}
});
const Parent = React.createClass({
doSomething: function(value) {
console.log('doSomething called by child with value:', value);
},
render: function() {
const childrenWithProps = React.Children.map(this.props.children,
(child) => React.cloneElement(child, {
doSomething: this.doSomething
})
);
return <div>{childrenWithProps}</div>
}
});
ReactDOM.render(
<Parent>
<Child value="1" />
<Child value="2" />
</Parent>,
document.getElementById('container')
);
1 Like