2018-10-25
react-use-localstorage
react, localstorage
react, localstorage
_Photo by Chris Scott on _Unsplash
React Hooks was just announced today at React Conf 2018.
You can check the official documentation
& also this dev.to article, Everything you need to know about React Hooks by Carl Vitullo
so I won't go into it further.
I created a simple hook called react-use-localstorage, which lets you store state in Local Storage.
You need to use following React versions.
It's bleeding edge and not recommended to use in production.
You can follow along on CodeSandbox.
First, install the package, react-use-localstorage.
https://gist.github.com/dance2die/0f4e5b5493593d2a903ac8dc7cda4088
And use it in a "Functional Component".
https://gist.github.com/dance2die/b98da9374585f1df9325bb279ce973f0
The demo shows that state is saved directly in local storage.
The source code is available on GitHub with MIT license.