Skip to content

@acoolhq/react-tiny-store


@acoolhq/react-tiny-store / batch

Function: batch() ​

batch(fn): void

Defined in: store.ts:80

Run several updates as a single batch so subscribers are notified once.

Parameters ​

fn ​

() => void

A batch function with setState calls inside it.

Returns ​

void

Example ​

ts
batch(() => {
  store.setState(p => ({ ...p, a: p.a + 1 }));
  store.setState(p => ({ ...p, b: p.b + 1 }));
}); // one notify after the batch