Update useDebounce.js
This commit is contained in:
parent
275f658b9d
commit
4a8982a91b
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user