robinweser / alveron

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

Make it work as a custom React Hook #11

Closed robinweser closed 5 years ago

robinweser commented 5 years ago

Could look something like:

const model = []
const actions = {
  setList: (_, items) => items
}
const effects = {
  fetch: (actions) => fetch(....).then(actions.setList)
}

const Store = createStore({ model, actions, effects })

const SomeList = () => {
  const { state, effects } = useAlveron(Store)

  return (
    <div>
      {state.map(el => <div>{el}</div>)}
      <button onClick={effects.fetch} />
    </div>
  )
}
robinweser commented 5 years ago

Has been implemented and is part of 3.0.0