global-state

v0.0.1arrow_drop_down
v0.0.1
STATUS
Passing
DOWNLOADS
157
VISIBILITY
Public
PUBLISHED
6 years ago
SIZE
N/A
1 contributor
Install global-state as a package?
Copied
npm i @bit/giladshoham.react-hooks.hooks.global-state
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.cloud
Component Example
React
React
Vue
Angular
React Native
Add dependency... help_outline
Just
import
any of the 1 million components
and packages in Bit or NPM to the example.
import Button from '@bit/grommet.grommet.button';
import Lodash from 'lodash';
toggle layout
chevron_left
chevron_right

react-hooks-global-state

Build Status npm version

Simple global state for React by Hooks API

Background

React Hooks API looks promising. This is an experimental library to use React Hooks API for global state.

Install

npm install react-hooks-global-state

Usage

import React from 'react';
import { createGlobalState } from 'react-hooks-global-state';

const initialState = { counter: 0 };
const { stateItemHooks } = createGlobalState(initialState);
const useCounter = stateItemHooks.counter;

const Counter = () => {
  const [value, update] = useCounter();
  return (
    <div>
      <span>Counter: {value}</span>
      <button onClick={() => update(v => v + 1)}>Click</button>
    </div>
  );
};

const App = () => (
  <div>
    <Counter />
    <Counter />
  </div>
);

Example

The examples folder contains a working example. You can run it with

PORT=8080 npm run examples:minimal

and open http://localhost:8080 in your web browser.

Blogs

Help and resources