Created
February 17, 2018 15:06
-
-
Save aofleejay/cc651bb2556405b66f46666f4f8bb09a to your computer and use it in GitHub Desktop.
localStorage module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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