Home > widget-integration > FilterStorageHelper > getSessionStorage
FilterStorageHelper.getSessionStorage() method
Gets a value from sessionStorage with type-safe JSON parsing.
Retrieves and parses a JSON value from sessionStorage. Returns the fallback value if storage is unavailable, key doesn't exist, or JSON parsing fails.
Signature:
getSessionStorage<T>(key: string, fallback: T): T;
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
key |
string |
The sessionStorage key to retrieve |
|
fallback |
T |
Fallback value returned if key doesn't exist or parsing fails |
Returns:
T
The parsed value of type T, or fallback
Remarks
Parsing errors are silently caught and return the fallback. This ensures graceful degradation when storage contains corrupted or invalid JSON.
Example
Override to add validation:
getSessionStorage<T>(key, fallback) {
const value = super.getSessionStorage(key, fallback);
// Validate against schema
if (!this.validateSchema(key, value)) {
console.warn(`Invalid schema for ${key}, using fallback`);
return fallback;
}
return value;
}