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) {
let cd = false;
export default function useDebounce(callback, delay = 500) {
let timer = null
return (...args) => {
if (cd) return;
cd = true;
if (timer) clearTimeout(timer);
timer = setTimeout(() => {
callback(...args);
setTimeout(() => {
cd = false;
timer = null;
}, delay);
}
}