2.0.1 • Published 6 years ago

god-state v2.0.1

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

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>
}
2.0.1

6 years ago

2.0.0

6 years ago

1.0.3

6 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.1.0

7 years ago