import { useEffect, useState } from 'react';
// 防抖 hooks
function useDebounce(value:any, delay = 300) {
const [debouncedValue, setDebouncedValue] = useState(value);
useEffect(() => {
const handler = window.setTimeout(() => {
setDebouncedValue(value)
}, delay)
return () => {
clearTimeout(handler);
}
}, [value, delay])
return debouncedValue;
}
export default useDebounce;
react hooks 写防抖函数(debounce)
最新推荐文章于 2024-10-10 15:54:39 发布