Update useDebounce.js

This commit is contained in:
huxuejian 2026-02-08 16:16:55 +08:00
parent 275f658b9d
commit 4a8982a91b

View File

@ -1,12 +1,11 @@
export default function useDebounce(callback, delay = 1000) { export default function useDebounce(callback, delay = 500) {
let cd = false; let timer = null
return (...args) => { return (...args) => {
if (cd) return; if (timer) clearTimeout(timer);
cd = true; timer = setTimeout(() => {
callback(...args); callback(...args);
setTimeout(() => { timer = null;
cd = false;
}, delay); }, delay);
} }
} }