class Child extends React.Component{
constructor(props){
super(props);
this.myRef=React.createRef();
}
componentDidMount(){
console.log(this.myRef.current);
}
render(){
return <input ref={this.myRef}/>
}
}
![](https://img2018.cnblogs.com/blog/1580958/201903/1580958-20190314173803943-720914757.png)
第二种方法
<input ref={(input) => {this.textInput = input;}} type="text" />