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