• Generates a signal using localStorage as the store. A shared Map is used if session storage is not supported.

    Type Parameters

    • T

      The type of the value that should be stored and deserialized.

    Parameters

    • initialValue: T

      the initial value for the signal

    • key: string

      the key to use in localStorage

    • options: WebStorageOptions<T> = {}

      optional options to configure the signal and underlying storage.

    Returns WritableSignal<T>

    the writable signal generated from storageSignal.

    const signal1 = localStorageSignal(1, 'someKey');
    console.log(signal1()); // This MIGHT not be 1 depending on what was stored in localStorage for "someKey".
    signal1.set(100);
    console.log(signal1()); // 100 ("someKey" is now 100 in localStorage)