refs有两种使用方法
一、是用回调函数
class Test extends Component {
testref() {
const el =this.codeValue;
}
render(){
return (
<div ref={(e) => { this.codeValue = e }}></div>
)
}
}
二、使用字符串
class Test extends Component {
testref() {
const el =this.refs.codeValue;
}
render(){
return (
<div ref=“codeValue”></div>
)
}
}
使用第二种方法的话,有时候eslint会报错,所以还是推荐使用第一种方法