Home > widget-integration > FilterStorageHelper > getLocalStorage

FilterStorageHelper.getLocalStorage() method

Gets a value from localStorage.

Retrieves a string value from localStorage with SSR-safe checks. Returns null if localStorage is unavailable or key doesn't exist.

Signature:

getLocalStorage(key: string): string | null;

Parameters

Parameter

Type

Description

key

string

The localStorage key to retrieve

Returns:

string | null

The stored string value, or null if not found or unavailable

Remarks

Safe to call in server-side rendering contexts. Always returns null when localStorage is undefined (SSR, private browsing, etc.).

Example

Override to add storage caching:

getLocalStorage(key) {
  // Check memory cache first
  const cached = this.storageCache.get(key);
  if (cached) return cached;

  const value = super.getLocalStorage(key);
  if (value) this.storageCache.set(key, value);
  return value;
}