Reactjs React-如何使用cloneElement以保留上下文
我正在使用React的未记录上下文功能。我注意到有一个警告,即只有显式调用组件时,此上下文功能才有效:Reactjs React-如何使用cloneElement以保留上下文,reactjs,Reactjs,我正在使用React的未记录上下文功能。我注意到有一个警告,即只有显式调用组件时,此上下文功能才有效: render() { return <div><SomeComponent /></div> } render(){ 返回 } 但是,如果克隆项目,则不会传递上下文: render() { return <div>{React.cloneElement(this.props.content)}</div> } rende
render() {
return <div><SomeComponent /></div>
}
render(){
返回
}
但是,如果克隆项目,则不会传递上下文:
render() {
return <div>{React.cloneElement(this.props.content)}</div>
}
render(){
返回{React.cloneElement(this.props.content)}
}
这是虫子吗?还是有什么方法可以让这项工作在我不知道的情况下进行?啊哈。显然在0.14之前,您需要使用
React.addons.cloneWithProps
来保存上下文。在0.14及以上时,反应。cloneElement
应完成此工作
参考: