use-global-storage

0.1.0 • Public • Published

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

Package Sidebar

Install

npm i use-global-storage

Weekly Downloads

23

Version

0.1.0

License

MIT

Unpacked Size

138 kB

Total Files

8

Last publish

Collaborators

  • embbnux