一、通常状况下父组件调用子组件的方法能够经过 ref 进行调用 redux
...... // 能够使用 this.Son.子组件的方法 来进行调用 render() { return ( <div> <Son ref ={ (element) => {this.Son = element} }> </div> ) ......
二、当子组件经过 redux 的 connect 高阶组件包裹时,不能经过以上方式直接读取到子组件,而读到的是包裹后的 Connect 组件app
解决办法以下:this
1)、首先在子组件在使用 connect 时须要填写第四个参数spa
...... export default connect(mapStateToPorops,mapDispatchToProps,null,{withRef: true})(Son) ......
2)、在父组件中调用时须要注意,调用 getWrappedInstance 方法后才能得到真正的 Son 组件code
...... // 能够使用 this.Son.子组件的方法 来进行调用 render() { return ( <div> <Son ref ={ (element) => {this.Son = element.getWrappedInstance()} }> </div> ) ......