@coreui/vue-pro
Version:
UI Components Library for Vue.js
24 lines (21 loc) • 834 B
JavaScript
import { ref, getCurrentScope, onScopeDispose } from 'vue';
const useDebouncedCallback = (callback, delay) => {
const timeout = ref();
const debouncedFn = (...args) => {
const handler = () => {
clearTimeout(timeout.value);
callback(...args);
};
clearTimeout(timeout.value);
timeout.value = setTimeout(handler, delay);
};
// Mirror VueUse's tryOnScopeDispose: register the cleanup only when called
// inside an active effect scope (a component setup). Calling it outside one
// is then a no-op instead of emitting a "no active effect scope" warning.
if (getCurrentScope()) {
onScopeDispose(() => clearTimeout(timeout.value));
}
return debouncedFn;
};
export { useDebouncedCallback };
//# sourceMappingURL=useDebouncedCallback.js.map