JSPM

react-localstorage-hook

0.1.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1384
  • Score
    100M100P100Q109537F
  • License MIT

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

npm package npm-bundle-size Module formats npm-download-count

  • 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