@menthays/easystate
TypeScript icon, indicating that this package has built-in type declarations

0.2.1 • Public • Published

EasyState

Easy state management based on React Context and Hooks

npm package

Install

npm install @menthays/easystate

Example

// store.js
import EasyState from '@menthays/easystate'
const CounterStore = EasyState({
  state: {
    count: 0
  },
  actions: {
    increment(state, {number}) {
      return {
        count: state.count + number
      }
    }
  }
});

export default CounterStore
// component
import CounterStore from 'path/to/store.js'
const {Provider, getState, getDispatcher} = CounterStore;

function CounterComponent() {
  const state = getState();
  const dispatch = getDispatcher();
  return (
    <Provider>
      <div onClick={() => dispatch('increment', {number: 3})}>Increment</div>
      <div>{state.count}</div>
    </Provider>
  )
}

Readme

Keywords

none

Package Sidebar

Install

npm i @menthays/easystate

Weekly Downloads

3

Version

0.2.1

License

MIT

Unpacked Size

8.7 kB

Total Files

7

Last publish

Collaborators

  • menthays