Home > widget-integration > FilterStorageHelper > setLocalStorage

FilterStorageHelper.setLocalStorage() method

Sets a value in localStorage.

Stores a string value in localStorage with SSR-safe checks. Never throws: on a quota error it reclaims space from Boost-owned keys and retries, and if there is still no room the write is skipped.

Signature:

setLocalStorage(key: string, value: string): void;

Parameters

Parameter

Type

Description

key

string

The localStorage key to set

value

string

The string value to store

Returns:

void

Remarks

Persistence is best-effort by design. Callers sit on critical paths such as filter initialization, so a full or unavailable storage must degrade to "preference not remembered", never to a thrown error that aborts rendering.

Example

Override to add expiration timestamps:

setLocalStorage(key, value) {
  // Add expiration metadata
  const dataWithExpiry = JSON.stringify({
    value,
    expires: Date.now() + this.getTTL(key)
  });
  super.setLocalStorage(key, dataWithExpiry);
}