不理解官方的一个faqlinkIfthefunctionyou’rememoizingisaneventhandlerandisn’tusedduringrendering上边这句话是官方的原话,但我觉得没什么道理...在我看来下面两种写法没有任何区别,请指点;importReact,{useState,useCallback,useEffect,useRef}from'react';functionForm(){const[text,updateText]=useState('');consttextRef=useRef();useEffect(()=>{textRef.current=text;//Writeittotheref});consthandleSubmit=useCallback(()=>{constcurrentText=textRef.current;//Readitfromtherefconsole.log(currentText);},[textRef]);//Don'trecreatehandleSubmitlike[text]woulddo//consthandleSubmit=useCallback(()=>{//console.log(text);//},[text]);return(<>updateText(e.target.value)}/> click >);}exportdefaultForm;
潇潇雨雨
慕丝7291255
相关分类