Function useSignalScope

  • React hook for managing an Alien Signals effect scope. Effects created within this scope are automatically cleaned up when the component unmounts.

    Type Parameters

    • T

      The return type of the callback within the scope.

    Parameters

    • callback: () => T

      A function that creates signal effects.

    Returns () => void

    A stop function to cancel the scoped effects.

    function ScopedEffects() {
    const stopScope = useSignalScope(() => {
    createEffect(() => {
    console.log('Scoped effect:', someSignal());
    });
    });

    // Optionally, you can stop the scope manually if needed:
    // useEffect(() => () => stopScope(), [stopScope]);

    return null;
    }