Skip to content

@statesync/persistence


@statesync/persistence / clearPersistedData

Function: clearPersistedData()

ts
function clearPersistedData<T>(storage, crossTabOptions?): Promise<void>;

Defined in: persistence/src/persistence-applier.ts:699

Clears all persisted data from the given storage backend and optionally notifies other tabs via BroadcastChannel.

If the storage backend does not implement clear(), this is a no-op for the storage part. Cross-tab notification is still sent if options are provided.

Type Parameters

Type ParameterDescription
TThe shape of the application state.

Parameters

ParameterTypeDescription
storageStorageBackend<T>The storage backend to clear.
crossTabOptions?CrossTabSyncOptionsIf provided, a temporary BroadcastChannel is opened to notify other tabs that storage was cleared, then immediately disposed.

Returns

Promise<void>

A promise that resolves when the storage has been cleared.

Example

typescript
await clearPersistedData(storage, { channelName: 'state-sync:settings' });

Released under the MIT License.