function useBatcher<TValue, TSelected>(
fn,
options?,
selector?): OctaneBatcher<TValue, TSelected>;Defined in: batcher/useBatcher.ts:84
Creates and retains the Batcher for its Octane owner.
Collects items and processes them together when maxSize, wait, or getShouldExecute triggers a batch. Use addItem to accumulate work and flush to process a partial batch.
Pass a selector to track only the state consumed by the owner. The default selection is {}, so utility state changes do not update the owner unless it opts in. Selection uses shallow comparison. The raw store remains available for additional subscriptions. Read selected state through utility.state. Use utility.Subscribe with a render callback to select state in a child without subscribing the owner.
Available state fields:
Pass an options object with property getters or a factory. Top-level properties are read reactively; function-valued core options remain callbacks. Local options override provider defaults. Updates retain the utility, its store, counters, and pending work. Unmounting the component calls cancel(). onUnmount replaces default cleanup and receives the same adapter instance. A custom callback must perform all required cleanup. Use flush() where supported to finish pending work.
TValue
TSelected = { }
(items) => void
Function executed by the utility.
OctanePacerOptions<OctaneBatcherOptions<TValue, TSelected>>
Core options or a reactive factory, plus an optional onUnmount callback.
(state) => TSelected
Selects state that updates the owner. Omit to leave selected state empty.
OctaneBatcher<TValue, TSelected>
The retained utility instance with selected state and child subscriptions.
import { useBatcher } from '@tanstack/octane-pacer'
const utility = useBatcher(
(items: Array<string>) => { console.log(items) },
{ maxSize: 5, wait: 1000 },
(state) => ({ size: state.size }),
)
utility.addItem('item')
// Selected state: utility.state.size