Home > widget-integration > FilterStorageHelper > setLocalStorage

FilterStorageHelper.setLocalStorage() method

Sets a value in localStorage.

Stores a string value in localStorage with SSR-safe checks. Silently fails if localStorage is unavailable.

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

Does not throw errors if storage is unavailable. Consider using isLocalStorageAvailable() first for critical operations that need to verify storage is accessible.

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);
}