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

1. 通过回调函数

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

 

2. 通过createRef函数

const currentRef = React.createRef();
<SomeComponent ref={currentRef} />

 

posted @ 2020-11-29 13:09  樊顺  阅读(223)  评论(0编辑  收藏  举报