Function createEffect

  • Creates a reactive effect that automatically re-runs when its tracked signals update.

    Type Parameters

    • T

      The return type of the effect function (typically void).

    Parameters

    • fn: () => T

      A function that will run whenever its tracked signals change.

    Returns () => void

    A stop function to cancel the effect.

    const count = createSignal(1);
    const stopEffect = createEffect(() => {
    console.log('Count is', count());
    });

    // To stop the effect:
    stopEffect();