You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP

redux-reactors

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-reactors

A small library for creating action/reducer combinations.

1.0.3
latest
Version published
Weekly downloads
169
-24.55%
Maintainers
1
Weekly downloads
 
Created

redux-reactors

A small library (~20 loc) for creating action/reducer combinations, also known as reactors.

build status npm version

Quickstart

Install the library

$ npm install redux-reactors --save

Add the store enhancer

import {reactorEnhancer} from 'redux-reactors';
import {createStore, compose} from 'redux';
// ...
const store = createStore(reducer, initialState, compose(reactorEnhancer, ...otherEnhancers));

Create reactors

import {createReactor} from 'redux-reactors';
export const incrementReactor = createReactor('INCREMENT', (state, action) => {
  return Object.assign({}, {
    counter: state.counter + action.payload,
    state,
  });
});

Use reactors in your components

import {incrementReactor} from './my-reactors';
import {connect} from 'react-redux';

function MyComponent(props) {
  const {increment, counter} = props;
  return (
    <div>
      <div>The count is {counter}</div>
      <button onClick={() => increment(1)}>Increment by one</button>
      <button onClick={() => increment(2)}>Increment by two</button>
    </div>
  );
}

const mapStateToProps = (state) => {
  return {
    counter: state.counter,
  };
};

// Since createReactor returns an action creator,
// you can use it easily with mapDispatchToProps
const mapDispatchToProps = {
  increment: incrementReactor,
};

export default connect(mapStateToProps, mapDispatchToProps)(MyComponent);

FAQs

Package last updated on 05 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts