Created
February 15, 2020 08:58
-
-
Save ericzakariasson/ac1512c91eaf370ce1b752c24381dc3a to your computer and use it in GitHub Desktop.
This file contains 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
function useLocalStorage() { | |
const get = key => localStorage.getItem(key); | |
const set = (key, value) = localStorage.setItem(key, value); | |
return [get, set]; | |
} | |
const Example = () => { | |
const [getLocalStorage, setLocalStorage] = useLocalStorage(); | |
const savedItem = getLocalStorage('some_key'); | |
return <div>{savedItem}</div> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment