andrefgneves / react-waterfall

React store built on top of the new context API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

react-waterfall

How to use it ?

yarn add react-waterfall

Here is an example of a basic implementation.

import { initStore } from 'react-waterfall'

const store = {
  initialState: { count: 0 },
  actions: {
    increment: ({ count }) => ({ count: count + 1 }),
  },
}

const { Provider, connect } = initStore(store)

let Count = ({ count, actions }) => (
  <>
    {count}
    <button onClick={actions.increment}>+</button>
  </>
)

Count = connect(state => ({ count: state.count }))(Count)

const App = () => (
  <Provider>
    <Count />
  </Provider>
)

You will find more examples here.

Redux DevTools

If you want you can use Redux DevTools with react-waterfall thanks to this middleware.

import { initStore } from 'react-waterfall'
import devtools from 'react-waterfall-redux-devtools-middleware'

const prod = process.env.NODE_ENV === 'production'

export const { Provider, connect } = initStore(store, !prod && devtools())

Types

You can explore types here

Advanced

Advanced examples are available here

Links

About

React store built on top of the new context API

License:MIT License


Languages

Language:JavaScript 100.0%