library_components/composables/useBounce.ts

11 lines
263 B
TypeScript
Raw Normal View History

2024-07-05 12:22:31 +00:00
export const useBounce = (): Function => {
let bounce: NodeJS.Timeout;
return function (callback: Function, timeout: number = 400) {
clearTimeout(bounce);
bounce = setTimeout(() => {
callback();
}, timeout);
};
};