Skip to content

Instantly share code, notes, and snippets.

@aofleejay
Created February 17, 2018 15:06
Show Gist options
  • Save aofleejay/cc651bb2556405b66f46666f4f8bb09a to your computer and use it in GitHub Desktop.
Save aofleejay/cc651bb2556405b66f46666f4f8bb09a to your computer and use it in GitHub Desktop.
localStorage module
const loadState = () => {
try {
const serializedState = localStorage.getItem('store')
if (serializedState === null) {
return undefined
} else {
return JSON.parse(serializedState)
}
} catch (error) {
return undefined
}
}
const saveState = (state) => {
try {
const serializedState = JSON.stringify(state)
localStorage.setItem('store', serializedState)
} catch (error) {
console.log(error.message)
}
}
export {
loadState,
saveState,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment