2026-01-19 18:52:18 +08:00
|
|
|
|
|
|
|
|
export default function useDebounce(callback, delay = 1000) {
|
2026-02-05 17:12:52 +08:00
|
|
|
let timer = null;
|
2026-01-19 18:52:18 +08:00
|
|
|
return (...args) => {
|
2026-02-05 17:12:52 +08:00
|
|
|
if (timer) clearTimeout(timer)
|
|
|
|
|
timer = setTimeout(() => {
|
|
|
|
|
callback(...args);
|
2026-01-19 18:52:18 +08:00
|
|
|
}, delay);
|
|
|
|
|
}
|
|
|
|
|
}
|