Skip to content

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
const batched = useBatchedCallback((batch) => console.log(batch), 5);
## Demo

Api

Parameters

NameTypeDefaultNote
callback(batch: Params[]) => void-The callback that receives a batch of calls
batchSizenumber-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

SourceDemo

Contributors

D
debabin
debabin

Released under the MIT License.