createBatch
Executes a function in a batch, ensuring that all signal updates within the function only trigger effects once at the end, instead of immediately after each update.
Signature
function createBatch(fn: () => void): void;Parameters
Example
const [x, setX] = createSignal(0);
const [y, setY] = createSignal(0);
createEffect(() => {
console.log("Sum:", x() + y());
});
// Without batching, the effect triggers twice
setX(1); // Log: Sum: 1
setY(2); // Log: Sum: 3
// With batching, it triggers only once
createBatch(() => {
setX(10);
setY(20);
}); // Log: Sum: 30Advanced Usage
Behavior
Use Cases
Performance Notes
Last updated