0.1.1 • Published 8 months ago

react-localstorage-hook v0.1.1

Weekly downloads
128
License
MIT
Repository
github
Last release
8 months ago

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

NameTypeDefaultRequiredDescription
keyStringnulltrueThe key that will be used when calling localStorage.setItem(key)and localStorage.getItem(key)
initialValueany''falseThe initial value of the data.

License

This project is licensed under the MIT License - see the LICENCE.md file for details