不知道能不能解决,试试这两种方法
1: 子组件为Children,在子组件创建时
componentDidMount() {
this.props.onRef(this);
}
然后父组件中
<Children
onRef={node => this.Children = node}
/>
然后可以打印this.Children看一下
2:
<Children ref={this.Children}/>
然后在
constructor(props) {
super(props);
this.Children = React.createRef();
}
然后可以打印this.Children看一下