react-hook-storage

0.1.2 • Public • Published

npm version npm downloads GitHub stars Travis Coverage Status MIT License


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>
    </>
  );
}

Package Sidebar

Install

npm i react-hook-storage

Weekly Downloads

0

Version

0.1.2

License

MIT

Unpacked Size

24.5 kB

Total Files

9

Last publish

Collaborators

  • alejandroledesma