The reason for customizingUseUpdate is that seEffect will trigger this event when the initial variable is undefined and becomes the value we assign it
const useUpdate = (fn,dep) =>{ const [count, setCount] = useState(0) useEffect(()=>{ setCount(x=>x+1) },[dep]) useEffect(()=>{ if(count>1){ fn() } },[count,fn]) } UseUpdate (()=>{console.log(' changed ')},n)Copy the code