lany9527 / react-redux-local

Add a local reducer to your application with ease.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

react-redux-local

Build Status Code Coverage version downloads MIT License

semantic-release All Contributors PRs Welcome Code of Conduct

Watch on GitHub Star on GitHub Tweet

Adding a local reducer can be very verbose with libraries like recompose, the goal of this library is to reduce boilerplate when creating a local reducer.

Table of Contents

Installation

This module is distributed via npm which is bundled with node and should be installed as one of your project's dependencies:

npm install --save react-redux-local
yarn add react-redux-local

Usage

import LocalReducer from 'react-redux-local'

const actions = {
  doSomething: () => ({ type: 'SOMETHING' })
}

// https://github.com/redux-saga/redux-saga
function * saga () {
  yield takeEvery('SOMETHING', () => console.log('Action with type SOMETHING was triggered'))
}

// https://github.com/zalmoxisus/redux-devtools-extension/blob/master/docs/API/Arguments.md#windowdevtoolsextensionconfig
const devToolsOptions = {}

const MyComponent = () => (
  <LocalReducer
    reducer={reducer}
    actions={actions}
    sagas={[saga]}
    devToolsOptions={devToolsOptions}
    render={(state, actions, dispatch) => {
      // state = redux state
      // actions = binded actions (no need to dispatch)
      // dispatch = optional dispatch function, if you need a more complex workflow
    }}
  />
)

Inspiration

Michael Jackson - Never Write Another HoC

Michael Jackson - Never Write Another HoC

Other Solutions

local-react-redux local-react-redux-saga react-local-reducer

Contributors

Thanks goes to these people:


Flávio Carvalho

This project follows the all-contributors specification. Contributions of any kind welcome!

LICENSE

MIT

About

Add a local reducer to your application with ease.

License:MIT License


Languages

Language:JavaScript 100.0%