Saltar al contenido principal

Function: useCreateStorageSignal()

useCreateStorageSignal<T>(key, fallbackValue, target?): [SignalGetter<T>, SignalSetter<T>]

Defined in: src/core/services/reactive.service.ts:234

Creates a signal that persists its value to a storage backend (localStorage, sessionStorage, etc.). Reads the initial value from storage on creation.

Type Parameters

T

T

The signal value type.

Parameters

key

string

Storage key.

fallbackValue

T

Value used when the key is not in storage.

target?

StorageTarget = "localStorage"

Storage backend (defaults to "localStorage").

Returns

[SignalGetter<T>, SignalSetter<T>]

A tuple of [getter, setter]. The setter writes through to storage.

Example

const [theme, setTheme] = useCreateStorageSignal("theme", "dark");
theme(); // "dark" (or whatever was stored)
setTheme("light"); // persists to localStorage