Skip to content

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

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 ​

Source • Demo

Contributors ​

D
debabin
debabin

Released under the MIT License.