qortal-ui/core/src/localStorageHelpers.js
2023-05-11 18:40:52 +02:00

20 lines
572 B
JavaScript

export const loadStateFromLocalStorage = (key) => {
try {
const config = localStorage.getItem(key)
if (config === null) return void 0
return JSON.parse(config)
} catch (e) {
// Could add error handling in case there's a weird one...don't want to overwrite config if it's malfunctioned
return void 0
}
}
export const saveStateToLocalStorage = (key, state) => {
try {
const stateJSON = JSON.stringify(state)
localStorage.setItem(key, stateJSON)
} catch (e) {
console.error(e, 'e')
}
}