React项目中推荐两种方式使用 ref

1. 通过回调函数

<SomeComponent ref={thisComp => this.yourCompRef = thisComp} />

2. 通过createRef函数

const currentRef = React.createRef();
<SomeComponent ref={currentRef} />
原文地址:https://www.cnblogs.com/fanqshun/p/14056061.html