save progress in local storage
parent
8dd3c09339
commit
206152a07c
@ -0,0 +1,19 @@
|
|||||||
|
const KEY = "progress";
|
||||||
|
export function loadState() {
|
||||||
|
try {
|
||||||
|
const serializedState = localStorage.getItem(KEY);
|
||||||
|
if (!serializedState) return undefined;
|
||||||
|
return JSON.parse(serializedState);
|
||||||
|
} catch (e) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function saveState(state: any) {
|
||||||
|
try {
|
||||||
|
const serializedState = JSON.stringify(state);
|
||||||
|
localStorage.setItem(KEY, serializedState);
|
||||||
|
} catch (e) {
|
||||||
|
// Ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue