Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { connect } from 'react-redux'
- import { actionC } from '../actions';
- import React from 'react';
- export default function (ComposedComponent, _mapStatetoProps, _mapDispatchToProps) {
- class SuperComponent extends React.PureComponent {
- componentWillMount(){
- this.props.registeredDispatchers.forEach((dispatcherName) => {
- this.props[dispatcherName]();
- });
- }
- render () {
- return <ComposedComponent {...this.props} {...this.boundActionCreators} />
- }
- }
- function mapStateToProps(state) {
- const {stateC} = state;
- const reducedState = _mapStatetoProps(state);
- return Object.assign({}, reducedState, {stateC});
- }
- const mapDispatchToProps = (dispatch) => {
- var functionsToBeDispatched = {
- ..._mapDispatchToProps(dispatch),
- actionC(){
- dispatch(actionC());
- }
- };
- functionsToBeDispatched.registeredDispatchers = Object.keys(functionsToBeDispatched)
- return functionsToBeDispatched;
- };
- return connect(mapStateToProps, mapDispatchToProps)(SuperComponent);
- }
Add Comment
Please, Sign In to add comment