1.0.4 • Published 4 years ago

global-hook v1.0.4

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

global-hook

Build Status

A global version of React's useState hook.

See a live example here: https://codesandbox.io/s/global-hook-example-jhdn6

Usage:

import useGlobalState from 'global-hook';
const initialState = 0;

function Counter() {
  const [count, setCount] = useGlobalState(initialState, 'uniqueNamespace');
  return (
    <div>
      <span>{count}</span>
      <button onClick={() => setCount(count + 1)}>+</button>
      <button onClick={() => setCount(count - 1)}>-</button>
    </div>
  );
}

If you prefer to create your own instance, use createUseGlobalState:

import { createUseGlobalState } from 'global-hook';
export const useGlobalState = createUseGlobalState();
1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.1

4 years ago