feat: store state in localStorage

This commit is contained in:
Deluan
2020-03-31 14:04:10 -04:00
parent 944f3695c4
commit 083a11a563
6 changed files with 140 additions and 39 deletions
+20
View File
@@ -0,0 +1,20 @@
export const loadState = () => {
try {
const serializedState = localStorage.getItem('state')
if (serializedState === null) {
return undefined
}
return JSON.parse(serializedState)
} catch (err) {
return undefined
}
}
export const saveState = (state) => {
try {
const serializedState = JSON.stringify(state)
localStorage.setItem('state', serializedState)
} catch (err) {
// Ignore write errors
}
}