1.0.1 • Published 4 years ago

react-local-storage-state v1.0.1

Weekly downloads
101
License
MIT
Repository
github
Last release
4 years ago

react-local-storage-state

Hook for persisting React state to local storage

Install

npm install react-local-storage-state

Usage

import useLocalStorageState from 'react-local-storage-state'

const [name, setName] = useLocalStorageState('name', 'm. nindra zaka')

API

Return Type

useLocalStorageState will return [value, setValue]. This is the same like React.useState

Parameters

key

type string

This is the key that will be used when saving and getting data from local storage. Make sure you use a unique name for different state

default value

type any

This is the default value that will be used for the state.