Skip to content

Instantly share code, notes, and snippets.

@cowboy
Last active February 25, 2020 20:53
Show Gist options
  • Save cowboy/915dcb22ab414f9aecbb5e6df8b2c41b to your computer and use it in GitHub Desktop.
Save cowboy/915dcb22ab414f9aecbb5e6df8b2c41b to your computer and use it in GitHub Desktop.
react-redux mapDispatchToProps helper
const reparse = require('../actions/reparse');
module.exports = function mapDispatchToPropsPlusReparse(fn) {
return function(dispatch, ownProps) {
function reparse() {
return dispatch(reparse(true));
}
return Object.assign({reparse: reparse}, fn ? fn(dispatch, ownProps) : {});
};
};
const mapDispatchToPropsPlusReparse = require('./dispatch-reparse');
// Just reparse
const mapDispatchToProps = mapDispatchToPropsPlusReparse();
module.exports = connect(null, mapDispatchToProps)(WhateverComponent);
const mapDispatchToPropsPlusReparse = require('./dispatch-reparse');
// reparse + foo (+ any others you want to add)
const mapDispatchToProps = mapDispatchToPropsPlusReparse(function(dispatch, ownProps) {
return {
foo: function(bar) {
dispatch(yay(bar));
},
};
});
module.exports = connect(null, mapDispatchToProps)(WhateverComponent);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment