1.0.1 • Published 5 years ago
react-global-state-lib v1.0.1
react-global-state-lib
Global state using Context & Hooks APIs
Table of Contents
Install
This project uses node and npm.
$ npm install react-global-state-lib
$ # OR
$ yarn add react-global-state-lib
Usage
import React, { Component } from 'react'
import initGlobalState from 'react-global-state-lib'
const {GlobalStateProvider, useGlobalState} = initGlobalState({
count: 1, // initial state
})
function Counter() {
const [global, setGlobalState] = useGlobalState()
return <h1>{global.count}</h1>
}
function IncrementBtn() {
const [global, setGlobalState] = useGlobalState()
return (
<button type="button" onClick={() => setGlobalState({count: global.count + 1})}>
+
</button>
)
}
function App() {
return (
<GlobalStateProvider>
<Counter />
<Counter />
<Counter />
<IncrementBtn />
</GlobalStateProvider>
)
}
export default App
Contribute
- Fork it and create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am "Add some feature"
- Push to the branch:
git push origin my-new-feature
- Submit a pull request
License
MIT © tiaanduplessis