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


sh
$ npm install redux-reactors --save
`$3
`javascript
import {reactorEnhancer} from 'redux-reactors';
import {createStore, compose} from 'redux';
// ...
const store = createStore(reducer, initialState, compose(reactorEnhancer, ...otherEnhancers));
`$3
`javascript
import {createReactor} from 'redux-reactors';
export const incrementReactor = createReactor('INCREMENT', (state, action) => {
return Object.assign({}, {
counter: state.counter + action.payload,
state,
});
});
`$3
`javascript
import {incrementReactor} from './my-reactors';
import {connect} from 'react-redux';function MyComponent(props) {
const {increment, counter} = props;
return (
The count is {counter}
);
}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);
``