Created
October 31, 2016 17:01
-
-
Save anyley/9ca134aee471d1b6ce151f91591a0622 to your computer and use it in GitHub Desktop.
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
export const loadState = (storage) => { | |
try { | |
const serializedState = localStorage.getItem(storage) | |
if (serializedState === null) | |
return undefined | |
return JSON.parse(serializedState) | |
} catch (error) { | |
return undefined | |
} | |
} | |
export const saveState = (storage, state) => { | |
try { | |
const serializedState = JSON.stringify(state) | |
localStorage.setItem(storage, serializedState) | |
} catch (error) { | |
// pass | |
} | |
} | |
export const clearStorage = () => { | |
localStorage.clear() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment