【发布时间】:2017-02-03 13:28:01
【问题描述】:
最初一切正常,我有一个类似的组件。 这个
class A extends React.Component {
constructor(props) {
super(props);
this.childRef = null
}
componentDidMount() {
this.childRef = this.refs.b
// now I can call child function like this
this.childRef.calledByParent()
}
render(){
<B ref = "b"/>
}
}
在其他文件中
class B extends React.Component {
calledByParent(){
console.log("i'm called")
}
render(){
<div> hello </div>
}
}
export default B
到这里它工作正常但是当我在class Bexport default connect(mapStateToProps, mapDispatchToProps)(B)做这样的事情时
它不工作。我已经从 react-redux 导入了连接
【问题讨论】:
-
有意义,因为
connect将另一个组件包裹在父组件周围。那么,问题是什么?
标签: reactjs redux react-redux