import { useEffect, useRef } from "react"; type EffectHookType = typeof useEffect; const createUpdateEffect: (effect: EffectHookType) => EffectHookType = (effect) => (callback, deps) => { const isMounted = useRef(false); // 处理刷新 effect(() => { return () => { isMounted.current = false; }; }, []); effect(() => { if (!isMounted.current) { isMounted.current = true; } else { return callback(); } }, deps); }; export default createUpdateEffect(useEffect);