父组件通过props把方法传递给子组件
class Parent extends React.Component {
getRef(ref){
this.node = ref
}
render(){
return(
<Children getRef = {this.getRef} />
)
}
}
子组件一旦创建就会执行ref的回调
function Children (props) {
return(
<>
<input ref={props.getRef} />
</>
)
}