2026-01-20 19:36:49 +08:00
|
|
|
|
2026-02-08 16:16:55 +08:00
|
|
|
export default function useDebounce(callback, delay = 500) {
|
|
|
|
|
let timer = null
|
2026-01-20 19:36:49 +08:00
|
|
|
return (...args) => {
|
2026-02-08 16:16:55 +08:00
|
|
|
if (timer) clearTimeout(timer);
|
|
|
|
|
timer = setTimeout(() => {
|
|
|
|
|
callback(...args);
|
|
|
|
|
timer = null;
|
2026-01-20 19:36:49 +08:00
|
|
|
}, delay);
|
|
|
|
|
}
|
|
|
|
|
}
|