MCPcopy Create free account
hub / github.com/developmentseed/stac-react / debounce

Function debounce

src/utils/debounce.ts:7–21  ·  view source on GitHub ↗
(fn: F, ms = 250)

Source from the content-addressed store, hash-verified

5};
6
7const debounce = <F extends (...args: any) => any>(fn: F, ms = 250): DebouncedFunction<F> => {
8 let timeoutId: ReturnType<typeof setTimeout>;
9
10 const debouncedFn = function (this: any, ...args: any[]) {
11 clearTimeout(timeoutId);
12 timeoutId = setTimeout(() => fn.apply(this, args), ms);
13 } as F;
14
15 // Add cancel method to clear pending timeouts
16 (debouncedFn as DebouncedFunction<F>).cancel = () => {
17 clearTimeout(timeoutId);
18 };
19
20 return debouncedFn as DebouncedFunction<F>;
21};
22
23export default debounce;
24export type { DebouncedFunction };

Callers 1

useStacSearchFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected