zach-local-storage-safe
v1.0.2
Published
power up window localStorage, with obj, array, string support, initialize data type, expire time
Downloads
4
Maintainers
Readme
zach-local-storage-safe
Power up browser localStorage function, with extra obj, array, string support, initialize data type, expire time.
Table of Contents
Install
# Yarn
yarn add zach-local-storage-safe
# NPM
npm install --save zach-local-storage-safe
Quick Start
// state initilize with localStorage
import {useState,useCallback} from 'react';
import locaslStorageSafe from 'zach-local-storage-safe';
const Example = () => {
const [state,setState] = useState(locaslStorageSafe.getItem('myState','object') );
const _onClick = useCallback((e)=>{
const id = e.target.getAttribute('data-id');
const data = {id};
locaslStorageSafe.setItem('myState',data,30000);
setState(()=>data)
},[])
return (
<div onClick={_onClick} data-id={state.id}>
Test
</div>
);
};
Usage
List
browsers supported
Related projects
Thanks
This repo was setup with the help of the excellent create-react-library
and redux-react-hook
.
Contributing
Zach Yu [email protected]
License
MIT