useBatchedCallback
Hook that batches calls and forwards them to a callback
utilities
medium
test coverage
Last changed: 5 days ago
Installation
Library
CLI
Manual
typescript
import { useBatchedCallback } from '@siberiacancode/reactuse';Usage
typescript
const delayed = useBatchedCallback((batch) => console.log(batch), { size: 5, delay: 1000 });Demo
Api
Parameters
| Name | Type | Default | Note |
|---|---|---|---|
| callback | (batch: Params[]) => void | - | The callback that receives a batch of calls |
| options.size | number | - | The batch settings with size and optional delay |
| options.delay? | number | 1000 | The delay (ms) after which pending calls are flushed |
Returns
BatchedCallback<Params>
Type declaration
typescript
export type BatchedCallback<Params extends unknown[]> = ((...args: Params) => void) & {
flush: () => void;
cancel: () => void;
};
export interface UseBatchedCallbackOptions {
delay?: number;
size: number;
}Source
Source • DemoContributors
D