god-state

2.0.1 • Public • Published

god-state

A small wrapper over React's Context API to simplify state management.


Example usage

Wrap your components with Provider and pass in some stores

import { Provider } from 'god-state'

const App = ({ children }) => (
  <Provider stores={{
    counter: { value: 0 }
  }}>
    {children}
  </Provider>
)

Then use stores by name anywhere in the app:

import { useStore } from 'god-state'

const CounterComponent = () => {
  const [counter, changeCounter] = useStore('counter')
  const increase = () => changeCounter({ value: counter.value + 1 })
  const decrease = () => changeCounter({ value: counter.value - 1 })

  return <div>
    Counter value: {counter.value}
    <button onClick={increase}>increase</button>
    <button onClick={decrease}>decrease</button>
  </div>
}

Package Sidebar

Install

npm i god-state

Weekly Downloads

6

Version

2.0.1

License

MIT

Unpacked Size

23.9 kB

Total Files

14

Last publish

Collaborators

  • microcood