useLocalStorage - React custom hook
React custom Hook to manage localStorage API.
Why useLocalStorage?
With this hook, you can handle your localStorage:
- Manage and use it as a simple React State.
- Don't need to call the Window interface.
TL;DR;
const [storageVariable, setStorageVariable] = useLocalStorage('storage data');
Usage
Just install:
npm install react-hook-uselocalstorage
And import the hook:
;
Use it in your component:
const App = { const storageVariable setStorageVariable = ; const inputRef = ; const clickHandler = { ; } return <div> <h2>storageVariable</h2> <input ref=inputRef type='text' /> <button onClick=clickHandler>Set</button> </div> }
LIVE Example
(Check it in deployed example)
License
MIT © franlol