useBatchedCallback
Hook that batches calls and forwards them to a callback
utilities
medium
test coverage
Last changed: last month
Installation
Library
CLI
Manual
typescript
import { useBatchedCallback } from '@siberiacancode/reactuse';Usage
typescript
## Demo const batched = useBatchedCallback((batch) => console.log(batch), 5);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