ref的三种使用方式
string ref
function
createRef
constructor(){super()this.objRef=React.createRef()// {current: null}}componentDidMount(){setTimeout(()=>{// {this.refs.ref1.textContent}// {this.ref2.textContent}// {this.ref3.textContent}this.refs.stringRef.textContent='striing ref got'this.methodRef.textContent='method ref got'this.objRef.current.textContent='obj ref got'},1000)}render(){return(<><pref="stringRef">span1</p><pref={ele=>(this.methodReef=ele)}>span3</p><pref={this.objRef}>span3</p></>)}importtype{RefObject}from'shared/ReactTypes';exportfunctioncreateRef(): RefObject{constcrfObject={current: null,};if(__DEV__){Object.seal(refObject);}returnrefObject;}