react-localstorage-hook
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

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

Package Sidebar

Install

npm i react-localstorage-hook

Weekly Downloads

726

Version

0.1.1

License

MIT

Unpacked Size

6.67 kB

Total Files

8

Last publish

Collaborators

  • kaansey