Created
August 12, 2018 21:31
-
-
Save suzdalnitski/5ad107cca157828c9a49f0e357d41a4d to your computer and use it in GitHub Desktop.
Simple HOC
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
const withLocalStorage = (WrappedComponent) => { | |
const loadFromStorage = (key) => localStorage.getItem(key); | |
const saveToStorage = (key, value) => localStorage.setItem(key, value); | |
const removeFromStorage = (key) => localStorage.removeItem(key); | |
return (props) => ( | |
<WrappedComponent | |
loadFromStorage={loadFromStorage} | |
saveToStorage={saveToStorage} | |
removeFromStorage={removeFromStorage} | |
{...props} | |
/> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment