Skip to content
0

katanakit-js / useDebounceImmediate

Function: useDebounceImmediate() ​

ts
function useDebounceImmediate<T>(func, delayMs): (...args) => void;

Defined in: src/core/services/timing.service.ts:194

Leading-edge debounce: fires immediately on the first call, then ignores calls until delayMs of quiet. Additional calls during the wait window schedule a single trailing invocation with the latest arguments.

Type Parameters ​

Type ParameterDescription
T extends (...args) => unknownThe wrapped function type.

Parameters ​

ParameterTypeDescription
funcTFunction to debounce.
delayMsnumberDebounce delay in milliseconds.

Returns ​

A debounced function with the same signature.

(...args) => void

Example ​

ts
const save = useDebounceImmediate(submitForm, 500);
save("a"); // fires immediately
save("b"); // queued
save("c"); // queued (replaces "b")
// after 500ms of quiet: fires with "c"

Released under the MIT License.