@rehmat-falcon/use-local-storage
v1.0.0
Published
>
Downloads
2
Readme
@rehmat-falcon/use-local-storage
This hook allows you to access the localstorage for a certain key.
Support for objects have been added. If your initial value is an object, it will deserialize when retrieving and serialize when saving the object.
Install
npm install --save @rehmat-falcon/use-local-storage
Usage
import React, { Component } from 'react'
import { useLocalStorage } from '@rehmat-falcon/use-local-storage';
const Example = () => {
const localStorageManager = useLocalStorage("key", {});
// check if the key exists using localStorageManager.state.exists
return (
<div>{localStorageManager.state.value}</div>
)
}
Hook Definition
useLocalStorage(key, initialValue = "", override = false);
key : The key in which to save the value
initialValue : The value to use if no value is present
override : If set to true, the initialValue will be saved into the localStorage by overriding the current value.
License
MIT © RehmatFalcon
This hook is created using create-react-hook.