0.1.0 • Published 5 years ago

use-global-storage v0.1.0

Weekly downloads
208
License
MIT
Repository
github
Last release
5 years ago

use-global-storage

NPM Version

React Hook to connect storage and state. You can use this as a global state manager in React.

Install

via npm:

npm install use-global-storage

via yarn:

yarn add use-global-storage

Usage

import useGlobalStorage from 'use-global-storage';

const useStorage = useGlobalStorage({
  storageOptions: { name: 'test-db' }
});

const Counter = () => {
  const [state, setState] = useStorage('counter');
  return (
    <div className="Counter">
      <p>
        Counter:
        {state || 0}
      </p>
      <button type="button" onClick={() => setState(state + 1)}>
        +1 to global
      </button>
    </div>
  );
};