robinweser / alveron

Tiny (0.8kb) Elm-inspired state management for React
https://alveron.js.org
MIT License
73 stars 2 forks source link

Wrapper component #8

Closed robinweser closed 6 years ago

robinweser commented 6 years ago

This PR adds a Wrapper component that is a convenient shorthand for the Provider, Consumer pair when working with local state.


const Counter = createStore({
  model: 0,
  actions: {
    increment: state => state + 1,
    decrement: state => state - 1,
  }
})

const Tree = () => (
  < Counter.Wrapper initialState={5}>
    {({ state, actions }) => (
      <div>
        <div>{state}</div>
        <button onClick={actions.increment}>+</button>
        <button onClick={actions.decrement}>-</button>
      </div>
    )}
  </Counter.Wrapper>
)