• Groups multiple signal updates into a single batch to avoid redundant computations.

    When multiple signals are updated within a batch, dependent computed values and effects will only run once at the end, improving performance.

    Isomorphic: Works identically across all JavaScript runtimes. Performance: Eliminates redundant computations from multiple updates. Synchronous: Batch completes before returning.

    Parameters

    • fn: (() => void)

      Function containing signal updates

        • (): void
        • Returns void

    Returns void

    const a = signal(1);
    const b = signal(2);
    const sum = computed(() => a() + b());

    effect(() => console.log("Sum:", sum()));

    // Without batch: logs "Sum: 3", "Sum: 5", "Sum: 9"
    a.set(2);
    b.set(3);
    a.set(4);

    // With batch: only logs "Sum: 9" once
    batch(() => {
    a.set(2);
    b.set(3);
    a.set(4);
    });