1 contributor
Like
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
and packages in Bit or NPM to the example. any of the 1 million componentstoggle layout
chevron_left
chevron_right
react-hooks-global-state
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.