Skip to content
0

katanakit-js / useCreateBatch

Function: useCreateBatch() ​

ts
function useCreateBatch(): (callback) => void;

Defined in: src/core/services/reactive.service.ts:304

Returns a batch function that defers signal notifications until the callback completes. Nested calls are supported -- only the outermost batch flushes the queue.

Returns ​

A batch(callback) function.

(callback) => void

Example ​

ts
const batch = useCreateBatch();
const [a, setA] = useCreateSignal(0);
const [b, setB] = useCreateSignal(0);

batch(() => {
  setA(1);
  setB(2);
  // listeners fire only once here, not twice
});

Released under the MIT License.