README
Introduction
React hook for manage the localStorage and sessionStorage.
Install
npm install react-hook-storage --save
or
yarn add react-hook-storage
Install
import ReactStorage from 'react-hook-storage'
const storage = new ReactStorage({
key: 'app:0.0.1', // default is 'react-hook-storage'
storage: 'local', // Select session|local storage. By default it's 'local'
})
export default storage
Usage
import React from 'react';
import { useStorage } from 'storage'
function StateCounter() {
const [count, setCount] = useStorage(0);
return (
<>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>+</button>
<button onClick={() => setCount(count - 1)}>-</button>
</>
);
}