React useLocalStorage
- It is an custom hook for browser localstorage management.
- For the same localstorage
key
It is consistent across the component (synchronize values between components). - serializer (JSON.stringify)
- deserializer (JSON.parse)
Demo
https://codesandbox.io/s/react-localstorage-hook-yfj5f
Installation
Add react-localstorage-hook
dependency
yarn add react-localstorage-hook
npm install react-localstorage-hook --save
Usage
import useLocalStorage from 'react-localstorage-hook'
const [values, setValue] = useLocalStorage(key, initialValue)
Options
Name | Type | Default | Required | Description |
---|
key | String | null | true | The key that will be used when calling localStorage.setItem(key)and localStorage.getItem(key) |
initialValue | any | '' | false | The initial value of the data. |
License
This project is licensed under the MIT License - see the
LICENCE.md file for details