diff options
Diffstat (limited to 'packages/anastasis-webui/src/hooks')
-rw-r--r-- | packages/anastasis-webui/src/hooks/use-anastasis-reducer.ts | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/packages/anastasis-webui/src/hooks/use-anastasis-reducer.ts b/packages/anastasis-webui/src/hooks/use-anastasis-reducer.ts index 110ec0166..27eab0884 100644 --- a/packages/anastasis-webui/src/hooks/use-anastasis-reducer.ts +++ b/packages/anastasis-webui/src/hooks/use-anastasis-reducer.ts @@ -235,10 +235,23 @@ export interface AnastasisReducerApi { runTransaction(f: (h: ReducerTransactionHandle) => Promise<void>): void; } +function storageGet(key: string): string | null { + if (typeof localStorage === "object") { + return localStorage.getItem(key); + } + return null; +} + +function storageSet(key: string, value: any): void { + if (typeof localStorage === "object") { + return localStorage.setItem(key, value); + } +} + function restoreState(): any { let state: any; try { - let s = localStorage.getItem("anastasisReducerState"); + let s = storageGet("anastasisReducerState"); if (s === "undefined") { state = undefined; } else if (s) { @@ -261,7 +274,7 @@ export function useAnastasisReducer(): AnastasisReducerApi { const setAnastasisState = (newState: AnastasisState) => { try { - localStorage.setItem( + storageSet( "anastasisReducerState", JSON.stringify(newState.reducerState), ); |