Skip to content

Instantly share code, notes, and snippets.

@jeffellis
Created March 14, 2018 16:34
Show Gist options
  • Save jeffellis/20cbad36e6396c3459853bf57bd27ba8 to your computer and use it in GitHub Desktop.
Save jeffellis/20cbad36e6396c3459853bf57bd27ba8 to your computer and use it in GitHub Desktop.
Michael's withDispatch wrapper
import React, { Component } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
const mapStateToProps = (state) => ({});
export function withDispatch(WrappedComponent, actions) {
class Dispatcher extends Component {
render() {
return <WrappedComponent { ...this.props} />;
}
}
const mapDispatchToProps = (dispatch) => bindActionCreators(actions, dispatch);
return connect(mapStateToProps, mapDispatchToProps)(Dispatcher);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment