Last active
February 25, 2020 20:53
-
-
Save cowboy/915dcb22ab414f9aecbb5e6df8b2c41b to your computer and use it in GitHub Desktop.
react-redux mapDispatchToProps helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) : {}); | |
}; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mapDispatchToPropsPlusReparse = require('./dispatch-reparse'); | |
// Just reparse | |
const mapDispatchToProps = mapDispatchToPropsPlusReparse(); | |
module.exports = connect(null, mapDispatchToProps)(WhateverComponent); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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