我正在尝试将额外的props传递给 this.props.children,我看到了这个答案how to pass props to children with React.cloneElement?
出于某种原因,虽然我没有收到任何错误,但我看不到props
所以我有这个状态
this.state = {
open: true
}
我想把它传递给 this.props.children,这就是我到目前为止所做的:
{
React.Children.map(this.props.children, child =>
React.cloneElement(child, {sidebarState: this.state.open}))
}
当我在孩子身上使用 console.logging this.props 时,我看不到我的新props。
--- 编辑 --- 在孩子中它看起来像这样:
render() {
console.log(this.props)
// other code
}
顺便说一句,我正在使用 react 16.0