Package Exports
- react-localstorage-hook
- react-localstorage-hook/dist/index.cjs.js
- react-localstorage-hook/dist/index.esm.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-localstorage-hook) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
React useLocalStorage
- It is an custom hook for browser localstorage management.
- For the same localstorage
keyIt 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 --saveUsage
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