save progress in local storage

This commit is contained in:
Alexander Bentkamp
2023-01-19 16:10:08 +01:00
parent 8dd3c09339
commit 206152a07c
6 changed files with 40 additions and 3 deletions
+19
View File
@@ -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
}
}