qortal-ui/qortal-ui-core/src/localStorageHelpers.js
2022-02-10 00:35:21 -08: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')
}
}