useBatchedCallback ​
Hook that batches calls and forwards them to a callback
utilities
medium
test coverage
Last changed: 3 minutes ago
Installation ​
Library
CLI
Manual
typescript
import { useBatchedCallback } from '@siberiacancode/reactuse';Usage ​
typescript
const batched = useBatchedCallback((batch) => console.log(batch), 5);Demo ​
Api ​
Parameters
| Name | Type | Default | Note |
|---|---|---|---|
| callback | (batch: Params[]) => void | - | The callback that receives a batch of calls |
| batchSize | number | - | The maximum size of a batch before it is flushed |
Returns
BatchedCallback<Params>
Type declaration ​
typescript
export type BatchedCallback<Params extends unknown[]> = ((...args: Params) => void) & {
flush: () => void;
cancel: () => void;
};Source ​
Source • DemoContributors ​
D