@himanshu-sorathiya/react-kit 1.0.27 → 1.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,85 +2,1094 @@
2
2
 
3
3
  import { Key } from 'react';
4
4
 
5
- export interface DebounceOptions {
5
+ /**
6
+ * Configuration for `useBatcher`.
7
+ *
8
+ * All three flush triggers (`maxSize`, `maxWait`, `quietPeriod`) are
9
+ * optional and independent — configure any combination, and whichever
10
+ * condition is met first triggers the flush. If none are configured, the
11
+ * batch only ever flushes when `flush()` is called manually.
12
+ */
13
+ export interface BatchOptions<Item> {
14
+ /**
15
+ * Flushes the batch immediately once it reaches this many items.
16
+ * Checked on every `add()` call, before either timer-based trigger is
17
+ * considered.
18
+ *
19
+ * Invalid input (not a positive number) is ignored — not clamped to a
20
+ * fallback — with a dev-mode warning, since there's no sensible
21
+ * default size to fall back to.
22
+ *
23
+ * @defaultValue `undefined` (no size ceiling)
24
+ */
25
+ maxSize?: number;
26
+ /**
27
+ * A hard ceiling, in milliseconds, on how long a batch can sit before
28
+ * flushing — measured from the moment the *first* item of the current
29
+ * batch was added, not the most recent one. Guarantees a maximum
30
+ * latency per item regardless of how long the batch keeps growing.
31
+ *
32
+ * Invalid input (not a non-negative number) is ignored with a dev-mode
33
+ * warning.
34
+ *
35
+ * @defaultValue `undefined` (no time ceiling)
36
+ */
6
37
  maxWait?: number;
7
- leading?: boolean;
8
- trailing?: boolean;
38
+ /**
39
+ * Flushes the batch once this many milliseconds pass with no further
40
+ * items added — resets on every `add()` call, unlike `maxWait`. Use
41
+ * this when you want to wait for activity to genuinely settle before
42
+ * flushing, rather than enforcing a hard per-item latency ceiling.
43
+ *
44
+ * If both `maxWait` and `quietPeriod` are configured and `quietPeriod`
45
+ * is not shorter than `maxWait`, `maxWait` will almost always win the
46
+ * race — a dev-mode warning flags this combination.
47
+ *
48
+ * Invalid input (not a non-negative number) is ignored with a dev-mode
49
+ * warning.
50
+ *
51
+ * @defaultValue `undefined` (no quiet-period trigger)
52
+ */
53
+ quietPeriod?: number;
54
+ /**
55
+ * Called with a snapshot of the current batch contents every time it
56
+ * changes — after every `add()`, and after every flush or `cancel()`
57
+ * (with an empty array). This is the mechanism for getting live,
58
+ * reactive access to what's currently queued (e.g. a "3 items
59
+ * queued…" indicator) without `useBatcher` itself needing to hold the
60
+ * full item list in React state.
61
+ *
62
+ * Safe to pass a fresh inline function on every render — it's captured
63
+ * in a ref and refreshed via effect, same as `onFlush`.
64
+ *
65
+ * @defaultValue `undefined`
66
+ */
67
+ onItemsChange?: (items: readonly Item[]) => void;
9
68
  }
10
- export interface UseDebounceReturn {
11
- run: <Args extends unknown[]>(func: (...args: Args) => void, ...args: Args) => void;
12
- cancel: () => void;
69
+ /**
70
+ * The object returned by `useBatcher`.
71
+ */
72
+ export interface UseBatcherReturn<Item> {
73
+ /**
74
+ * Adds `item` to the current batch. Never rejected, never deferred to
75
+ * a future call — the item is always accepted immediately. Depending
76
+ * on the configured triggers, this may also cause an immediate flush
77
+ * (e.g. if `maxSize` is now reached).
78
+ */
79
+ add: (item: Item) => void;
80
+ /**
81
+ * Immediately flushes whatever is currently batched, bypassing
82
+ * `maxWait`/`quietPeriod` entirely. A no-op if the batch is empty —
83
+ * `onFlush` is never called with zero items.
84
+ */
13
85
  flush: () => void;
86
+ /**
87
+ * Discards the current batch entirely, without ever calling
88
+ * `onFlush`. Clears any pending timers.
89
+ */
90
+ cancel: () => void;
91
+ /**
92
+ * Suspends all automatic flush triggers (`maxSize`, `maxWait`,
93
+ * `quietPeriod`). Items added via `add()` while paused still
94
+ * accumulate normally — pausing stops the flushing machinery, not the
95
+ * accumulation. The only way to flush while paused is a manual
96
+ * `flush()` call.
97
+ */
98
+ pause: () => void;
99
+ /**
100
+ * Resumes automatic flushing. If the batch already meets `maxSize`
101
+ * (because items kept arriving while paused), flushes immediately.
102
+ * Otherwise, re-arms `maxWait`/`quietPeriod` timers from scratch —
103
+ * pausing does not preserve partial progress toward either deadline;
104
+ * resuming starts a fresh clock for whatever's still batched.
105
+ */
106
+ resume: () => void;
107
+ /** The number of items currently in the batch. */
108
+ size: number;
109
+ /** `true` whenever `size > 0`. */
14
110
  isPending: boolean;
111
+ /** `true` after `pause()`, until the next `resume()`. */
112
+ isPaused: boolean;
15
113
  }
16
- export declare function useDebounce(delay: number, options?: DebounceOptions): UseDebounceReturn;
114
+ /**
115
+ * Groups rapid, individual `add()` calls into batches, flushing the whole
116
+ * accumulated group to `onFlush` at once — instead of debouncing,
117
+ * throttling, or rate-limiting, all of which discard some calls along the
118
+ * way. Nothing added to a `useBatcher` is ever dropped; it's only ever
119
+ * grouped.
120
+ *
121
+ * A batch flushes when any configured trigger fires first: reaching
122
+ * `maxSize` items, `maxWait` milliseconds since the batch's first item,
123
+ * or `quietPeriod` milliseconds of no new items. All three are optional
124
+ * and can be combined freely. If none are configured, only a manual
125
+ * `flush()` call ever empties the batch.
126
+ *
127
+ * Unlike the debounce/throttle/rate-limit hook families, there's no
128
+ * separate `Callback`/`State`/`Value` wrapper — `onFlush` is a single
129
+ * fixed handler (captured in a ref and always current, so a fresh inline
130
+ * function on every render is safe), and live access to the current batch
131
+ * contents is available via the `onItemsChange` option instead of a
132
+ * dedicated hook.
133
+ *
134
+ * @example
135
+ * ```tsx
136
+ * function AnalyticsProvider({ children }: { children: React.ReactNode }) {
137
+ * const { add } = useBatcher<AnalyticsEvent>(
138
+ * (events) => sendAnalyticsBatch(events),
139
+ * { maxSize: 20, maxWait: 5000 },
140
+ * );
141
+ *
142
+ * // `track` can be called as often as needed — events are grouped and
143
+ * // sent in batches of up to 20, at least once every 5 seconds.
144
+ * const track = (event: AnalyticsEvent) => add(event);
145
+ *
146
+ * return (
147
+ * <AnalyticsContext.Provider value={{ track }}>
148
+ * {children}
149
+ * </AnalyticsContext.Provider>
150
+ * );
151
+ * }
152
+ * ```
153
+ *
154
+ * @param onFlush - Called with every item accumulated since the last
155
+ * flush, as a snapshot array. Safe to pass a fresh inline function on
156
+ * every render.
157
+ * @param options - See {@link BatchOptions}.
158
+ * @returns See {@link UseBatcherReturn}.
159
+ */
160
+ export declare function useBatcher<Item>(onFlush: (items: readonly Item[]) => void, options?: BatchOptions<Item>): UseBatcherReturn<Item>;
161
+ /**
162
+ * Adds an optional custom equality comparator to any hook that manages a
163
+ * value and needs to decide whether a "new" value is actually different
164
+ * enough to justify a re-render.
165
+ *
166
+ * Used by the `State` and `Value` variants of debounce/throttle/rate-limit
167
+ * (e.g. `useDebouncedValue`, `useThrottledState`) to avoid committing a
168
+ * value that is deeply/semantically equal to the value already held,
169
+ * which would otherwise trigger a wasted re-render.
170
+ *
171
+ * @example
172
+ * ```tsx
173
+ * useDebouncedValue(user, 300, {
174
+ * equalityFn: (previous, next) => previous.id === next.id,
175
+ * });
176
+ * ```
177
+ */
178
+ export interface EqualityFnOption<T> {
179
+ /**
180
+ * Called with the currently-held value and the candidate next value.
181
+ * Return `true` if they should be treated as equal (no update should be
182
+ * committed); return `false` to allow the update through.
183
+ *
184
+ * Defaults to `Object.is` when omitted, or when an invalid (non-function)
185
+ * value is provided — see the consuming hook's dev-mode warning.
186
+ */
187
+ equalityFn?: (previous: T, next: T) => boolean;
188
+ }
189
+ /**
190
+ * Configuration for `useDebouncer` and every hook built on top of it.
191
+ *
192
+ * @remarks
193
+ * `leading` and `trailing` may both be set to `false` at the same time —
194
+ * the hook will not silently correct this for you. That configuration
195
+ * means the debounced function will never run; a dev-mode warning is
196
+ * logged to help catch it early, but the choice itself is respected.
197
+ */
198
+ export interface DebounceOptions {
199
+ /**
200
+ * A hard ceiling, in milliseconds, on how long invocation can be
201
+ * deferred. If a continuous stream of calls keeps pushing the trailing
202
+ * timer out, `maxWait` forces a synchronous invocation once this many
203
+ * milliseconds have elapsed since the current cycle began — regardless
204
+ * of whether the trailing window has settled yet.
205
+ *
206
+ * Only evaluated at the moment `run()` is called; it is not an
207
+ * independent background timer, so it can't fire while no calls are
208
+ * coming in.
209
+ *
210
+ * @defaultValue `undefined` (no ceiling)
211
+ */
212
+ maxWait?: number;
213
+ /**
214
+ * When `true`, invokes on the leading edge — immediately, on the first
215
+ * call of a new debounce cycle (i.e. when no cycle is currently active).
216
+ *
217
+ * @defaultValue `false`
218
+ */
219
+ leading?: boolean;
220
+ /**
221
+ * When `true`, invokes on the trailing edge — once `delay` milliseconds
222
+ * have elapsed with no further calls.
223
+ *
224
+ * Defaults to `true` regardless of `leading`'s value. With
225
+ * `{ leading: true, trailing: true }` (both edges enabled), a single
226
+ * isolated call only fires once (the leading edge) — the trailing edge
227
+ * only fires if at least one more call arrives before the window
228
+ * closes.
229
+ *
230
+ * @defaultValue `true`
231
+ */
232
+ trailing?: boolean;
233
+ }
234
+ /**
235
+ * Options for `useDebouncedState`: all of {@link DebounceOptions}, plus an
236
+ * optional equality comparator used to skip committing a value equivalent
237
+ * to the one already held.
238
+ */
239
+ export type UseDebouncedStateOptions<T> = DebounceOptions & EqualityFnOption<T>;
240
+ /**
241
+ * Options for `useDebouncedValue`: all of {@link DebounceOptions}, plus an
242
+ * optional equality comparator used to skip committing a value equivalent
243
+ * to the one already held.
244
+ */
245
+ export type UseDebouncedValueOptions<T> = DebounceOptions & EqualityFnOption<T>;
246
+ /**
247
+ * The object returned by `useDebouncedCallback`.
248
+ */
17
249
  export interface UseDebouncedCallbackReturn<Args extends unknown[]> {
250
+ /**
251
+ * A stable, debounced wrapper around `func`. Safe to call from any
252
+ * event handler; internally always invokes the most recently rendered
253
+ * `func`, even though `debouncedFunc`'s own identity doesn't change
254
+ * across re-renders.
255
+ */
18
256
  debouncedFunc: (...args: Args) => void;
257
+ /** See {@link UseDebouncerReturn.cancel}. */
19
258
  cancel: () => void;
259
+ /** See {@link UseDebouncerReturn.flush}. */
20
260
  flush: () => void;
261
+ /** See {@link UseDebouncerReturn.isPending}. */
21
262
  isPending: boolean;
22
263
  }
264
+ /**
265
+ * Debounces a single function.
266
+ *
267
+ * `func` is captured in a ref and refreshed on every render — you can pass
268
+ * a fresh inline closure every time without resetting the pending debounce
269
+ * cycle, and the debounced wrapper always calls the *latest* `func`,
270
+ * closing over whatever props/state were current when it actually fires
271
+ * (never a stale closure from whenever the wrapper was first created).
272
+ *
273
+ * @example
274
+ * ```tsx
275
+ * function SearchBox() {
276
+ * const { debouncedFunc: handleSearch, isPending } = useDebouncedCallback(
277
+ * (query: string) => fetchResults(query),
278
+ * 400,
279
+ * );
280
+ *
281
+ * return (
282
+ * <>
283
+ * <input onChange={(e) => handleSearch(e.target.value)} />
284
+ * {isPending && <span>Typing…</span>}
285
+ * </>
286
+ * );
287
+ * }
288
+ * ```
289
+ *
290
+ * @param func - The function to debounce. Safe to pass a new closure on
291
+ * every render.
292
+ * @param delay - See {@link useDebouncer}.
293
+ * @param options - See {@link DebounceOptions}.
294
+ * @returns See {@link UseDebouncedCallbackReturn}.
295
+ */
23
296
  export declare function useDebouncedCallback<Args extends unknown[]>(func: (...args: Args) => void, delay: number, options?: DebounceOptions): UseDebouncedCallbackReturn<Args>;
297
+ /**
298
+ * The tuple returned by `useDebouncedState`, mirroring `useState`'s
299
+ * `[value, setValue]` shape with a third element carrying debounce
300
+ * controls.
301
+ */
24
302
  export type UseDebouncedStateReturn<T> = [
303
+ /** The current, committed state value. */
304
+ T,
305
+ /**
306
+ * Schedules a debounced update to state. Accepts either a plain value
307
+ * or a `useState`-style functional updater (`(previous) => next`).
308
+ *
309
+ * The functional-updater form composes correctly across multiple rapid
310
+ * calls made before the debounce settles — e.g. calling
311
+ * `setValue((p) => p + 1)` three times in a row schedules a cumulative
312
+ * `+3`, not three competing `+1`s racing to be "the" pending value.
313
+ * `previous` in that case refers to the most recently *scheduled*
314
+ * value, not necessarily the currently-committed state — this matters
315
+ * if you're chaining updates faster than the debounce settles.
316
+ */
317
+ (value: T | ((previous: T) => T)) => void,
318
+ {
319
+ /** See {@link UseDebouncerReturn.isPending}. */
320
+ isPending: boolean;
321
+ /**
322
+ * Cancels any pending debounced update. Also resyncs the internal
323
+ * "next value to commit" tracking back to the current committed
324
+ * state, so a subsequent functional update starts from the right
325
+ * baseline instead of building on a discarded value.
326
+ */
327
+ cancel: () => void;
328
+ /** See {@link UseDebouncerReturn.flush}. */
329
+ flush: () => void;
330
+ /**
331
+ * Bypasses debounce scheduling entirely and applies the value (or
332
+ * updater) immediately. Also cancels any debounced update that was
333
+ * still pending, so it can't land afterward and silently overwrite
334
+ * this forced value.
335
+ */
336
+ forceSetValue: (value: T | ((previous: T) => T)) => void;
337
+ }
338
+ ];
339
+ /**
340
+ * A `useState`-shaped hook whose setter defers its effect on state until
341
+ * the debounce window settles, instead of applying immediately.
342
+ *
343
+ * @example
344
+ * ```tsx
345
+ * function NoteEditor() {
346
+ * const [note, setNote, { isPending, flush, forceSetValue }] =
347
+ * useDebouncedState("", 800);
348
+ *
349
+ * return (
350
+ * <>
351
+ * <textarea onChange={(e) => setNote(e.target.value)} />
352
+ * <p>Committed: {note}</p>
353
+ * {isPending && <span>Unsaved changes…</span>}
354
+ * <button onClick={flush}>Save Now</button>
355
+ * <button onClick={() => forceSetValue("")}>Reset</button>
356
+ * </>
357
+ * );
358
+ * }
359
+ * ```
360
+ *
361
+ * @param initialValue - Initial state value, or a `useState`-style lazy
362
+ * initializer function (`() => T`).
363
+ * @param delay - See {@link useDebouncer}.
364
+ * @param options - See {@link UseDebouncedStateOptions}.
365
+ * @returns See {@link UseDebouncedStateReturn}.
366
+ */
367
+ export declare function useDebouncedState<T>(initialValue: T | (() => T), delay: number, options?: UseDebouncedStateOptions<T>): UseDebouncedStateReturn<T>;
368
+ /**
369
+ * The tuple returned by `useDebouncedValue`.
370
+ */
371
+ export type UseDebouncedValueReturn<T> = [
372
+ /** The debounced (lagging) mirror of the source value. */
25
373
  T,
26
- (value: T) => void,
27
374
  {
375
+ /** See {@link UseDebouncerReturn.isPending}. */
28
376
  isPending: boolean;
377
+ /** Cancels the pending sync to the latest source value. */
29
378
  cancel: () => void;
379
+ /** Immediately commits the latest source value, bypassing the delay. */
30
380
  flush: () => void;
31
- forceSetValue: (value: T) => void;
32
381
  }
33
382
  ];
34
- export declare function useDebouncedState<T>(initialValue: T | (() => T), delay: number, options?: DebounceOptions): UseDebouncedStateReturn<T>;
35
- export type UseDebouncedValueReturn<T> = T;
36
- export declare function useDebouncedValue<T>(value: T, delay: number, options?: DebounceOptions): UseDebouncedValueReturn<T>;
383
+ /**
384
+ * Mirrors `value`, but the mirror only updates `delay` milliseconds after
385
+ * `value` stops changing — a safe, stable dependency for an expensive
386
+ * effect (filtering, fetching) that shouldn't re-run on every keystroke.
387
+ *
388
+ * @example
389
+ * ```tsx
390
+ * function ProductFilterField() {
391
+ * const [query, setQuery] = useState("");
392
+ * const [debouncedQuery] = useDebouncedValue(query, 350);
393
+ *
394
+ * // `debouncedQuery` only updates 350ms after typing stops.
395
+ *
396
+ * return (
397
+ * <input value={query} onChange={(e) => setQuery(e.target.value)} />
398
+ * );
399
+ * }
400
+ * ```
401
+ *
402
+ * @param value - The source value to debounce. Every change re-arms the
403
+ * debounce window.
404
+ * @param delay - See {@link useDebouncer}.
405
+ * @param options - See {@link UseDebouncedValueOptions}.
406
+ * @returns See {@link UseDebouncedValueReturn}.
407
+ */
408
+ export declare function useDebouncedValue<T>(value: T, delay: number, options?: UseDebouncedValueOptions<T>): UseDebouncedValueReturn<T>;
409
+ /**
410
+ * The object returned by `useDebouncer`.
411
+ */
412
+ export interface UseDebouncerReturn {
413
+ /**
414
+ * Registers `func` (with `args`) as the function this debounce cycle
415
+ * will invoke, and (re)arms the debounce timer.
416
+ *
417
+ * Each call to `run()` accepts its own function — you are not locked
418
+ * into debouncing a single, fixed callback. If `run()` is called again
419
+ * before the pending timer fires, the previously-registered function
420
+ * and arguments are discarded entirely in favor of the new ones (a
421
+ * "last write wins" swap, not a queue).
422
+ *
423
+ * @example
424
+ * ```ts
425
+ * const { run } = useDebouncer(300);
426
+ *
427
+ * run((query: string) => fetchResults(query), searchTerm);
428
+ * ```
429
+ */
430
+ run: <Args extends unknown[]>(func: (...args: Args) => void, ...args: Args) => void;
431
+ /**
432
+ * Clears the pending timer and discards whatever function/arguments
433
+ * were registered via `run()`, without invoking anything. Sets
434
+ * `isPending` back to `false`.
435
+ */
436
+ cancel: () => void;
437
+ /**
438
+ * If a function is currently pending invocation, invokes it immediately
439
+ * (with its most recently registered arguments) and clears the timer.
440
+ * If nothing is pending, this is a no-op.
441
+ */
442
+ flush: () => void;
443
+ /**
444
+ * `true` whenever a trailing invocation is still scheduled to happen
445
+ * when the current cycle settles. `false` once it's known nothing
446
+ * further will fire — including immediately after a leading-edge
447
+ * invocation if `trailing` is disabled, not merely once the full window
448
+ * elapses.
449
+ */
450
+ isPending: boolean;
451
+ }
452
+ /**
453
+ * The debounce engine underlying every hook in this family.
454
+ *
455
+ * `useDebouncer` is a low-level scheduling primitive: a single timer and a
456
+ * single "next function to run" slot. Calling `run(func, ...args)`
457
+ * registers `func` as the occupant of that slot; if `run()` is called
458
+ * again before the timer fires, the new function/arguments replace the old
459
+ * ones outright.
460
+ *
461
+ * Most consumers won't reach for this directly — `useDebouncedCallback`,
462
+ * `useDebouncedState`, and `useDebouncedValue` are thin, purpose-built
463
+ * wrappers around it for the common cases (debouncing one fixed callback,
464
+ * a piece of state, or an incoming value). Use `useDebouncer` directly when
465
+ * you need the "swap, don't queue" behavior across genuinely different
466
+ * functions — see the example below.
467
+ *
468
+ * @example
469
+ * ```tsx
470
+ * function DocumentActionBar() {
471
+ * const { run, isPending } = useDebouncer(1000);
472
+ *
473
+ * const handleSave = () => run(() => saveDocument());
474
+ * const handleCancel = () => run(() => discardChanges());
475
+ *
476
+ * return (
477
+ * <>
478
+ * <button onClick={handleSave}>Save</button>
479
+ * <button onClick={handleCancel}>Cancel</button>
480
+ * {isPending && <span>Pending…</span>}
481
+ * </>
482
+ * );
483
+ * }
484
+ * ```
485
+ *
486
+ * @param delay - Milliseconds to wait before a trailing invocation fires.
487
+ * Coerced to a non-negative number; invalid input falls back to `0` with a
488
+ * dev-mode warning.
489
+ * @param options - See {@link DebounceOptions}.
490
+ * @returns See {@link UseDebouncerReturn}.
491
+ */
492
+ export declare function useDebouncer(delay: number, options?: DebounceOptions): UseDebouncerReturn;
493
+ /**
494
+ * Configuration for `useRateLimiter` and every hook built on top of it.
495
+ */
37
496
  export interface RateLimitOptions {
497
+ /**
498
+ * Called whenever a call is rejected because no executions remain in
499
+ * the current window.
500
+ *
501
+ * Safe to pass a fresh inline function on every render — it's captured
502
+ * in a ref and refreshed via effect, so it never causes the underlying
503
+ * timers to reset.
504
+ *
505
+ * @defaultValue `undefined`
506
+ */
38
507
  onRateLimitReached?: () => void;
508
+ /**
509
+ * Determines how the allowance replenishes once consumed.
510
+ *
511
+ * - `"burst"` — fixed window. All executions reset to the full `limit`
512
+ * at once, only once the entire `windowMs` duration has elapsed
513
+ * since the window began.
514
+ * - `"gradual"` — trickle refill. Executions return proportionately as
515
+ * time passes (`windowMs / limit` per execution), with no hard reset
516
+ * boundary.
517
+ *
518
+ * @defaultValue `"burst"`
519
+ */
39
520
  refillStrategy?: "burst" | "gradual";
40
521
  }
41
- export interface UseRateLimitReturn {
42
- run: <Args extends unknown[]>(func: (...args: Args) => void, ...args: Args) => void;
522
+ /**
523
+ * Options for `useRateLimitedState`: all of {@link RateLimitOptions}, plus
524
+ * an optional equality comparator used to skip committing a value
525
+ * equivalent to the one already held.
526
+ */
527
+ export type UseRateLimitedStateOptions<T> = RateLimitOptions & EqualityFnOption<T>;
528
+ /**
529
+ * Options for `useRateLimitedValue`: all of {@link RateLimitOptions}, plus
530
+ * an optional equality comparator used to skip committing a value
531
+ * equivalent to the one already held.
532
+ */
533
+ export type UseRateLimitedValueOptions<T> = RateLimitOptions & EqualityFnOption<T>;
534
+ /**
535
+ * The object returned by `useRateLimitedCallback`.
536
+ */
537
+ export interface UseRateLimitedCallbackReturn<Args extends unknown[]> {
538
+ /**
539
+ * A stable, rate-limited wrapper around `func`. Always invokes the
540
+ * most recently rendered `func`, even though `rateLimitedFunc`'s own
541
+ * identity doesn't change across re-renders.
542
+ *
543
+ * @returns `true` if `func` was invoked, `false` if the call was
544
+ * rejected because the allowance is exhausted.
545
+ */
546
+ rateLimitedFunc: (...args: Args) => boolean;
547
+ /** See {@link UseRateLimiterReturn.reset}. */
548
+ reset: () => void;
549
+ /** See {@link UseRateLimiterReturn.remaining}. */
43
550
  remaining: number;
551
+ /** See {@link UseRateLimiterReturn.isRateLimited}. */
44
552
  isRateLimited: boolean;
45
553
  }
46
- export declare function useRateLimit(limit: number, windowMs: number, options?: RateLimitOptions): UseRateLimitReturn;
47
- export interface UseRateLimitedCallbackReturn<Args extends unknown[]> {
48
- rateLimitedFunc: (...args: Args) => void;
554
+ /**
555
+ * Rate-limits a single function.
556
+ *
557
+ * `func` is captured in a ref and refreshed on every render — you can
558
+ * pass a fresh inline closure every time without resetting the
559
+ * underlying allowance tracking, and the wrapper always calls the
560
+ * *latest* `func`.
561
+ *
562
+ * @example
563
+ * ```tsx
564
+ * function SearchBox() {
565
+ * const { rateLimitedFunc, isRateLimited } = useRateLimitedCallback(
566
+ * (query: string) => fetch(`/api/search?q=${query}`),
567
+ * 10,
568
+ * 60_000,
569
+ * { refillStrategy: "gradual" },
570
+ * );
571
+ *
572
+ * return (
573
+ * <input
574
+ * disabled={isRateLimited}
575
+ * onChange={(e) => rateLimitedFunc(e.target.value)}
576
+ * />
577
+ * );
578
+ * }
579
+ * ```
580
+ *
581
+ * @param func - The function to rate-limit. Safe to pass a new closure
582
+ * on every render.
583
+ * @param limit - See {@link useRateLimiter}.
584
+ * @param windowMs - See {@link useRateLimiter}.
585
+ * @param options - See {@link RateLimitOptions}.
586
+ * @returns See {@link UseRateLimitedCallbackReturn}.
587
+ */
588
+ export declare function useRateLimitedCallback<Args extends unknown[]>(func: (...args: Args) => void, limit: number, windowMs: number, options?: RateLimitOptions): UseRateLimitedCallbackReturn<Args>;
589
+ /**
590
+ * The tuple returned by `useRateLimitedState`, mirroring `useState`'s
591
+ * `[value, setValue]` shape with a third element carrying rate-limit
592
+ * controls.
593
+ */
594
+ export type UseRateLimitedStateReturn<T> = [
595
+ /** The current, committed state value. */
596
+ T,
597
+ /**
598
+ * Attempts to update state. Accepts either a plain value or a
599
+ * `useState`-style functional updater (`(previous) => next`).
600
+ *
601
+ * Unlike the debounce/throttle `State` variants, nothing here is ever
602
+ * deferred — the update either applies immediately (against the
603
+ * genuinely current state, via React's own functional `setState`) or
604
+ * is rejected outright and state doesn't change at all. There's no
605
+ * "most recently scheduled value" to reason about, since nothing is
606
+ * ever queued.
607
+ *
608
+ * @returns `true` if the update was applied, `false` if it was
609
+ * rejected because the allowance is exhausted.
610
+ */
611
+ (value: T | ((previous: T) => T)) => boolean,
612
+ {
613
+ /** See {@link UseRateLimiterReturn.remaining}. */
614
+ remaining: number;
615
+ /** See {@link UseRateLimiterReturn.isRateLimited}. */
616
+ isRateLimited: boolean;
617
+ /** See {@link UseRateLimiterReturn.reset}. */
618
+ reset: () => void;
619
+ /**
620
+ * Bypasses rate-limit enforcement entirely and applies the value
621
+ * (or updater) immediately. Does not consume any of the allowance.
622
+ */
623
+ forceSetValue: (value: T | ((previous: T) => T)) => void;
624
+ }
625
+ ];
626
+ /**
627
+ * A `useState`-shaped hook whose setter can be rejected once the
628
+ * allowance for the current window is exhausted, instead of always
629
+ * applying.
630
+ *
631
+ * @example
632
+ * ```tsx
633
+ * function GenerationDemo() {
634
+ * const [result, generate, { remaining, isRateLimited }] =
635
+ * useRateLimitedState<string | null>(null, 3, 60_000);
636
+ *
637
+ * const handleGenerate = () => {
638
+ * if (!generate(`Result #${Math.random()}`)) {
639
+ * toast("Free limit reached — try again in a minute.");
640
+ * }
641
+ * };
642
+ *
643
+ * return (
644
+ * <>
645
+ * <button onClick={handleGenerate} disabled={isRateLimited}>
646
+ * Generate ({remaining} left)
647
+ * </button>
648
+ * <p>{result}</p>
649
+ * </>
650
+ * );
651
+ * }
652
+ * ```
653
+ *
654
+ * @param initialValue - Initial state value, or a `useState`-style lazy
655
+ * initializer function (`() => T`).
656
+ * @param limit - See {@link useRateLimiter}.
657
+ * @param windowMs - See {@link useRateLimiter}.
658
+ * @param options - See {@link UseRateLimitedStateOptions}.
659
+ * @returns See {@link UseRateLimitedStateReturn}.
660
+ */
661
+ export declare function useRateLimitedState<T>(initialValue: T | (() => T), limit: number, windowMs: number, options?: UseRateLimitedStateOptions<T>): UseRateLimitedStateReturn<T>;
662
+ /**
663
+ * The tuple returned by `useRateLimitedValue`.
664
+ */
665
+ export type UseRateLimitedValueReturn<T> = [
666
+ /** The rate-limited mirror of the source value. */
667
+ T,
668
+ {
669
+ /** See {@link UseRateLimiterReturn.remaining}. */
670
+ remaining: number;
671
+ /** See {@link UseRateLimiterReturn.isRateLimited}. */
672
+ isRateLimited: boolean;
673
+ /** See {@link UseRateLimiterReturn.reset}. */
674
+ reset: () => void;
675
+ }
676
+ ];
677
+ /**
678
+ * Mirrors `value`, but the mirror updates at most `limit` times per
679
+ * `windowMs` window.
680
+ *
681
+ * @remarks
682
+ * This has a meaningfully weaker guarantee than `useDebouncedValue` /
683
+ * `useThrottledValue`. Those hooks eventually deliver the *latest* value
684
+ * once their window settles, even if intermediate values were skipped.
685
+ * This hook does not — once the allowance is exhausted, incoming changes
686
+ * to `value` are dropped outright until the allowance refills, with no
687
+ * queueing and no catch-up. The mirror simply stays frozen at whatever it
688
+ * last committed until it's allowed to update again.
689
+ *
690
+ * @example
691
+ * ```tsx
692
+ * function NotificationFeed({ latestNotification }: { latestNotification: string }) {
693
+ * const [visibleNotification] = useRateLimitedValue(latestNotification, 3, 10_000);
694
+ *
695
+ * // At most 3 notifications surface per 10s window; any beyond that
696
+ * // are silently dropped rather than queued for later display.
697
+ *
698
+ * return <Toast message={visibleNotification} />;
699
+ * }
700
+ * ```
701
+ *
702
+ * @param value - The source value to rate-limit. Every change is subject
703
+ * to the current allowance.
704
+ * @param limit - See {@link useRateLimiter}.
705
+ * @param windowMs - See {@link useRateLimiter}.
706
+ * @param options - See {@link UseRateLimitedValueOptions}.
707
+ * @returns See {@link UseRateLimitedValueReturn}.
708
+ */
709
+ export declare function useRateLimitedValue<T>(value: T, limit: number, windowMs: number, options?: UseRateLimitedValueOptions<T>): UseRateLimitedValueReturn<T>;
710
+ /**
711
+ * The object returned by `useRateLimiter`.
712
+ */
713
+ export interface UseRateLimiterReturn {
714
+ /**
715
+ * Attempts to invoke `func` (with `args`) against the current
716
+ * allowance.
717
+ *
718
+ * Unlike `useDebouncer`/`useThrottler`, nothing here is ever deferred —
719
+ * every call to `run()` resolves synchronously, right now: either an
720
+ * execution is available and `func` runs immediately, or it isn't and
721
+ * `func` doesn't run at all (no queueing, no later catch-up).
722
+ *
723
+ * Each call accepts its own function, so a single `useRateLimiter`
724
+ * instance can gate several different actions against one shared
725
+ * allowance if needed.
726
+ *
727
+ * @returns `true` if `func` was invoked, `false` if the call was
728
+ * rejected because the current window's allowance is exhausted.
729
+ *
730
+ * @example
731
+ * ```ts
732
+ * const { run } = useRateLimiter(3, 10_000);
733
+ *
734
+ * const didFire = run(() => submitForm());
735
+ * if (!didFire) showToast("Too many attempts — please wait.");
736
+ * ```
737
+ */
738
+ run: <Args extends unknown[]>(func: (...args: Args) => void, ...args: Args) => boolean;
739
+ /**
740
+ * Immediately restores the full allowance and clears any in-progress
741
+ * background refill, bypassing the normal window/refill timing
742
+ * entirely. Useful after an unrelated event that should grant a fresh
743
+ * allowance outright — e.g. a successful CAPTCHA, or a plan upgrade.
744
+ */
745
+ reset: () => void;
746
+ /**
747
+ * The number of executions currently available. Kept accurate in real
748
+ * time — including while idle, with no further calls to `run()` —
749
+ * by a self-scheduling background timer that mirrors whichever
750
+ * `refillStrategy` is configured.
751
+ */
49
752
  remaining: number;
753
+ /** Convenience flag, equivalent to `remaining === 0`. */
50
754
  isRateLimited: boolean;
51
755
  }
52
- export declare function useRateLimitedCallback<Args extends unknown[]>(func: (...args: Args) => void, limit: number, windowMs: number, options?: RateLimitOptions): UseRateLimitedCallbackReturn<Args>;
756
+ /**
757
+ * The rate-limiting engine underlying every hook in this family.
758
+ *
759
+ * `useRateLimiter` grants up to `limit` executions per `windowMs` window,
760
+ * replenished according to `refillStrategy`. Unlike debounce or throttle,
761
+ * it never delays or reshapes *when* something runs — every call is an
762
+ * immediate accept-or-reject decision against the current allowance.
763
+ *
764
+ * Most consumers won't reach for this directly — `useRateLimitedCallback`,
765
+ * `useRateLimitedState`, and `useRateLimitedValue` are thin, purpose-built
766
+ * wrappers around it for the common cases.
767
+ *
768
+ * @example
769
+ * ```tsx
770
+ * function SubmitButton() {
771
+ * const { run, remaining, isRateLimited } = useRateLimiter(3, 10_000, {
772
+ * refillStrategy: "burst",
773
+ * onRateLimitReached: () => toast("Too many attempts."),
774
+ * });
775
+ *
776
+ * return (
777
+ * <button onClick={() => run(submitForm)} disabled={isRateLimited}>
778
+ * Submit ({remaining} left)
779
+ * </button>
780
+ * );
781
+ * }
782
+ * ```
783
+ *
784
+ * @param limit - Maximum executions allowed per window. Coerced to a
785
+ * non-negative integer with a floor of `1`; invalid input falls back to
786
+ * `1` with a dev-mode warning.
787
+ * @param windowMs - Length of the rate-limit window, in milliseconds.
788
+ * Coerced to a non-negative number; invalid input falls back to `0` with
789
+ * a dev-mode warning. A value of `0` disables rate limiting entirely
790
+ * (every call is allowed) rather than causing a division error — also
791
+ * dev-warned, since it's rarely intentional.
792
+ * @param options - See {@link RateLimitOptions}.
793
+ * @returns See {@link UseRateLimiterReturn}.
794
+ */
795
+ export declare function useRateLimiter(limit: number, windowMs: number, options?: RateLimitOptions): UseRateLimiterReturn;
796
+ /**
797
+ * Configuration for `useThrottler` and every hook built on top of it.
798
+ *
799
+ * @remarks
800
+ * `leading` and `trailing` may both be set to `false` at the same time —
801
+ * the hook will not silently correct this for you. That configuration
802
+ * means the throttled function will never run; a dev-mode warning is
803
+ * logged to help catch it early, but the choice itself is respected.
804
+ */
53
805
  export interface ThrottleOptions {
806
+ /**
807
+ * When `true`, invokes immediately on the first call of a new cooldown
808
+ * window.
809
+ *
810
+ * @defaultValue `true`
811
+ */
54
812
  leading?: boolean;
813
+ /**
814
+ * When `true`, invokes once more at the end of the cooldown window,
815
+ * using the most recently passed function/arguments — but only if at
816
+ * least one call arrived after the leading edge fired. A single
817
+ * isolated call with both edges enabled only fires once.
818
+ *
819
+ * @defaultValue `true`
820
+ */
55
821
  trailing?: boolean;
56
822
  }
57
- export interface UseThrottleReturn {
58
- run: <Args extends unknown[]>(func: (...args: Args) => void, ...args: Args) => void;
59
- cancel: () => void;
60
- flush: () => void;
61
- isPending: boolean;
62
- }
63
- export declare function useThrottle(delay: number, options?: ThrottleOptions): UseThrottleReturn;
823
+ /**
824
+ * Options for `useThrottledState`: all of {@link ThrottleOptions}, plus an
825
+ * optional equality comparator used to skip committing a value equivalent
826
+ * to the one already held.
827
+ */
828
+ export type UseThrottledStateOptions<T> = ThrottleOptions & EqualityFnOption<T>;
829
+ /**
830
+ * Options for `useThrottledValue`: all of {@link ThrottleOptions}, plus an
831
+ * optional equality comparator used to skip committing a value equivalent
832
+ * to the one already held.
833
+ */
834
+ export type UseThrottledValueOptions<T> = ThrottleOptions & EqualityFnOption<T>;
835
+ /**
836
+ * The object returned by `useThrottledCallback`.
837
+ */
64
838
  export interface UseThrottledCallbackReturn<Args extends unknown[]> {
839
+ /**
840
+ * A stable, throttled wrapper around `func`. Safe to attach directly
841
+ * to an event listener; internally always invokes the most recently
842
+ * rendered `func`, even though `throttledFunc`'s own identity doesn't
843
+ * change across re-renders.
844
+ */
65
845
  throttledFunc: (...args: Args) => void;
846
+ /** See {@link UseThrottlerReturn.cancel}. */
66
847
  cancel: () => void;
848
+ /** See {@link UseThrottlerReturn.flush}. */
67
849
  flush: () => void;
850
+ /** See {@link UseThrottlerReturn.isPending}. */
68
851
  isPending: boolean;
69
852
  }
853
+ /**
854
+ * Throttles a single function.
855
+ *
856
+ * `func` is captured in a ref and refreshed on every render — you can pass
857
+ * a fresh inline closure every time without resetting the running cooldown
858
+ * window, and the throttled wrapper always calls the *latest* `func`,
859
+ * closing over whatever props/state were current when it actually fires
860
+ * (never a stale closure from whenever the wrapper was first created).
861
+ *
862
+ * @example
863
+ * ```tsx
864
+ * function WindowSizeLogger() {
865
+ * const { throttledFunc: handleResize } = useThrottledCallback(
866
+ * () => console.log("width:", window.innerWidth),
867
+ * 200,
868
+ * );
869
+ *
870
+ * useEffect(() => {
871
+ * window.addEventListener("resize", handleResize);
872
+ * return () => window.removeEventListener("resize", handleResize);
873
+ * }, [handleResize]);
874
+ *
875
+ * return null;
876
+ * }
877
+ * ```
878
+ *
879
+ * @param func - The function to throttle. Safe to pass a new closure on
880
+ * every render.
881
+ * @param delay - See {@link useThrottler}.
882
+ * @param options - See {@link ThrottleOptions}.
883
+ * @returns See {@link UseThrottledCallbackReturn}.
884
+ */
70
885
  export declare function useThrottledCallback<Args extends unknown[]>(func: (...args: Args) => void, delay: number, options?: ThrottleOptions): UseThrottledCallbackReturn<Args>;
886
+ /**
887
+ * The tuple returned by `useThrottledState`, mirroring `useState`'s
888
+ * `[value, setValue]` shape with a third element carrying throttle
889
+ * controls.
890
+ */
71
891
  export type UseThrottledStateReturn<T> = [
892
+ /** The current (throttled) state value. */
72
893
  T,
73
- (value: T) => void,
894
+ /**
895
+ * Schedules a throttled update to state. Accepts either a plain value
896
+ * or a `useState`-style functional updater (`(previous) => next`).
897
+ *
898
+ * The functional-updater form composes correctly across multiple rapid
899
+ * calls made before the cooldown window settles — e.g. calling
900
+ * `setValue((p) => p + 1)` three times in a row schedules a cumulative
901
+ * `+3`, not three competing `+1`s racing to be "the" pending value.
902
+ * `previous` in that case refers to the most recently *scheduled*
903
+ * value, not necessarily the currently-committed state — this matters
904
+ * if you're chaining updates faster than the window settles.
905
+ */
906
+ (value: T | ((previous: T) => T)) => void,
74
907
  {
908
+ /** See {@link UseThrottlerReturn.isPending}. */
75
909
  isPending: boolean;
910
+ /**
911
+ * Cancels any pending throttled update. Also resyncs the internal
912
+ * "next value to commit" tracking back to the current committed
913
+ * state, so a subsequent functional update starts from the right
914
+ * baseline instead of building on a discarded value.
915
+ */
76
916
  cancel: () => void;
917
+ /** See {@link UseThrottlerReturn.flush}. */
77
918
  flush: () => void;
78
- forceSetValue: (value: T) => void;
919
+ /**
920
+ * Bypasses throttle scheduling entirely and applies the value (or
921
+ * updater) immediately. Also cancels any throttled update that was
922
+ * still pending, so it can't land afterward and silently overwrite
923
+ * this forced value.
924
+ */
925
+ forceSetValue: (value: T | ((previous: T) => T)) => void;
79
926
  }
80
927
  ];
81
- export declare function useThrottledState<T>(initialValue: T | (() => T), delay: number, options?: ThrottleOptions): UseThrottledStateReturn<T>;
82
- export type UseThrottledValueReturn<T> = T;
83
- export declare function useThrottledValue<T>(value: T, delay: number, options?: ThrottleOptions): UseThrottledValueReturn<T>;
928
+ /**
929
+ * A `useState`-shaped hook whose setter rate-limits its effect on state
930
+ * instead of applying immediately.
931
+ *
932
+ * @example
933
+ * ```tsx
934
+ * function ScoreBoard() {
935
+ * const [score, setScore, { flush, forceSetValue, isPending }] =
936
+ * useThrottledState(() => expensiveInitialScore(), 500);
937
+ *
938
+ * return (
939
+ * <>
940
+ * <p>Score: {score}</p>
941
+ * <button onClick={() => setScore((s) => s + 1)}>+1 (throttled)</button>
942
+ * <button onClick={flush}>Flush pending update</button>
943
+ * <button onClick={() => forceSetValue(0)}>Reset instantly</button>
944
+ * {isPending && <span>update queued…</span>}
945
+ * </>
946
+ * );
947
+ * }
948
+ * ```
949
+ *
950
+ * @param initialValue - Initial state value, or a `useState`-style lazy
951
+ * initializer function (`() => T`).
952
+ * @param delay - See {@link useThrottler}.
953
+ * @param options - See {@link UseThrottledStateOptions}.
954
+ * @returns See {@link UseThrottledStateReturn}.
955
+ */
956
+ export declare function useThrottledState<T>(initialValue: T | (() => T), delay: number, options?: UseThrottledStateOptions<T>): UseThrottledStateReturn<T>;
957
+ /**
958
+ * The tuple returned by `useThrottledValue`.
959
+ */
960
+ export type UseThrottledValueReturn<T> = [
961
+ /** The throttled (rate-limited) mirror of the source value. */
962
+ T,
963
+ {
964
+ /** See {@link UseThrottlerReturn.isPending}. */
965
+ isPending: boolean;
966
+ /** Cancels the pending sync to the latest source value. */
967
+ cancel: () => void;
968
+ /** Immediately commits the latest source value, bypassing the wait. */
969
+ flush: () => void;
970
+ }
971
+ ];
972
+ /**
973
+ * Mirrors `value`, but the mirror updates at most once every `delay`
974
+ * milliseconds — a safe, rate-limited dependency for an expensive
975
+ * downstream render (chart, canvas, map) driven by a fast-changing source
976
+ * like a slider or live coordinates.
977
+ *
978
+ * @remarks
979
+ * With the default `{ leading: true }`, the mirror updates almost
980
+ * immediately on the first change — throttle is about limiting *rate*,
981
+ * not deferring the first response the way debounce does.
982
+ *
983
+ * @example
984
+ * ```tsx
985
+ * function SliderDemo() {
986
+ * const [raw, setRaw] = useState(0);
987
+ * const [throttled] = useThrottledValue(raw, 100);
988
+ *
989
+ * return (
990
+ * <>
991
+ * <input
992
+ * type="range"
993
+ * value={raw}
994
+ * onChange={(e) => setRaw(Number(e.target.value))}
995
+ * />
996
+ * <HeavyPreview value={throttled} />
997
+ * </>
998
+ * );
999
+ * }
1000
+ * ```
1001
+ *
1002
+ * @param value - The source value to throttle. Every change is subject to
1003
+ * the cooldown window.
1004
+ * @param delay - See {@link useThrottler}.
1005
+ * @param options - See {@link UseThrottledValueOptions}.
1006
+ * @returns See {@link UseThrottledValueReturn}.
1007
+ */
1008
+ export declare function useThrottledValue<T>(value: T, delay: number, options?: UseThrottledValueOptions<T>): UseThrottledValueReturn<T>;
1009
+ /**
1010
+ * The object returned by `useThrottler`.
1011
+ */
1012
+ export interface UseThrottlerReturn {
1013
+ /**
1014
+ * Registers `func` (with `args`) as the function this cooldown window
1015
+ * will invoke.
1016
+ *
1017
+ * Each call to `run()` accepts its own function — you are not locked
1018
+ * into throttling a single, fixed callback. If a trailing invocation is
1019
+ * still pending when `run()` is called again, the previously-registered
1020
+ * function and arguments are replaced by the new ones — whichever call
1021
+ * was most recent before the window closes is the one that fires (a
1022
+ * "last write wins" swap, not a queue).
1023
+ *
1024
+ * @example
1025
+ * ```ts
1026
+ * const { run } = useThrottler(200);
1027
+ *
1028
+ * run((x: number, y: number) => logPosition(x, y), clientX, clientY);
1029
+ * ```
1030
+ */
1031
+ run: <Args extends unknown[]>(func: (...args: Args) => void, ...args: Args) => void;
1032
+ /**
1033
+ * Clears any pending trailing invocation and resets the cooldown
1034
+ * window entirely — the next call to `run()` is treated as the start
1035
+ * of a fresh window. Sets `isPending` back to `false`.
1036
+ */
1037
+ cancel: () => void;
1038
+ /**
1039
+ * If a trailing invocation is currently pending, invokes it
1040
+ * immediately (with its most recently registered arguments) and clears
1041
+ * the timer. If nothing is pending, this is a no-op.
1042
+ */
1043
+ flush: () => void;
1044
+ /**
1045
+ * `true` whenever a trailing invocation is still scheduled to fire
1046
+ * before the current cooldown window closes. `false` once it's known
1047
+ * nothing further will happen — including right after a leading-edge
1048
+ * invocation with no follow-up call yet, not merely once the whole
1049
+ * window elapses.
1050
+ */
1051
+ isPending: boolean;
1052
+ }
1053
+ /**
1054
+ * The throttle engine underlying every hook in this family.
1055
+ *
1056
+ * `useThrottler` is a low-level scheduling primitive: a single cooldown
1057
+ * window and a single "next function to run" slot. Unlike debounce,
1058
+ * additional calls that arrive mid-window do not push the window out
1059
+ * further — they just update which function/arguments will fire when the
1060
+ * *existing* window closes. This is what keeps a continuous stream of
1061
+ * calls (mousemove, scroll, resize) firing at a steady cadence instead of
1062
+ * only ever firing once activity stops.
1063
+ *
1064
+ * Most consumers won't reach for this directly — `useThrottledCallback`,
1065
+ * `useThrottledState`, and `useThrottledValue` are thin, purpose-built
1066
+ * wrappers around it for the common cases. Use `useThrottler` directly
1067
+ * when you need the "swap, don't queue" behavior across genuinely
1068
+ * different functions.
1069
+ *
1070
+ * @example
1071
+ * ```tsx
1072
+ * function ActivityLogger() {
1073
+ * const { run, isPending } = useThrottler(1000);
1074
+ *
1075
+ * return (
1076
+ * <div
1077
+ * onMouseMove={(e) => run(logMouseMove, e.clientX, e.clientY)}
1078
+ * onKeyDown={(e) => run(logKeyPress, e.key)}
1079
+ * >
1080
+ * {isPending ? "Recording…" : "Idle"}
1081
+ * </div>
1082
+ * );
1083
+ * }
1084
+ * ```
1085
+ *
1086
+ * @param delay - Length of the cooldown window, in milliseconds. Coerced
1087
+ * to a non-negative number; invalid input falls back to `0` with a
1088
+ * dev-mode warning.
1089
+ * @param options - See {@link ThrottleOptions}.
1090
+ * @returns See {@link UseThrottlerReturn}.
1091
+ */
1092
+ export declare function useThrottler(delay: number, options?: ThrottleOptions): UseThrottlerReturn;
84
1093
  export type ScrollAlign = "start" | "center" | "end" | "auto";
85
1094
  export type Axis = "vertical" | "horizontal";
86
1095
  export interface ScrollToOffsetOptions {