Skip to content

@statesync/persistence


@statesync/persistence / LocalStorageBackendOptions

Interface: LocalStorageBackendOptions ​

Defined in: persistence/src/storage/local-storage.ts:10

Configuration options for the localStorage storage backend.

Allows customization of the storage key and serialization behavior used when persisting snapshot data to the browser's localStorage API.

Properties ​

deserialize()? ​

ts
optional deserialize: (data) => SnapshotEnvelope<unknown>;

Defined in: persistence/src/storage/local-storage.ts:37

Custom deserialization function for converting a stored string back into a snapshot envelope.

Parameters ​

ParameterTypeDescription
datastringThe raw string retrieved from localStorage.

Returns ​

SnapshotEnvelope<unknown>

The deserialized snapshot envelope.

Default ​

ts
JSON.parse

key ​

ts
key: string;

Defined in: persistence/src/storage/local-storage.ts:17

The key under which snapshot data is stored in localStorage.

Must be unique per application or state instance to avoid collisions with other data stored in the same origin's localStorage.


serialize()? ​

ts
optional serialize: (snapshot) => string;

Defined in: persistence/src/storage/local-storage.ts:27

Custom serialization function for converting a snapshot envelope into a string suitable for localStorage storage.

Parameters ​

ParameterTypeDescription
snapshotSnapshotEnvelope<unknown>The snapshot envelope to serialize.

Returns ​

string

A string representation of the snapshot.

Default ​

ts
JSON.stringify

Released under the MIT License.