1.0.1 • Published 7 years ago
dispatch-pass-through v1.0.1
Dispatch pass-through
1 line utility mostly useful for react-redux. Specifically for
mapDispatchToProps, which passes all arguments passed to a dispatch-wrapped action prop through to the action itself.
Why?
I got sick of writing almost identical mapDispatchToProps statements in which I would just pass all arguments through to the action.
Before (without dispatchPassThrough)
const mapDispatchToProps = dispatch => ({
setStuff: (foo, bar) => dispatch(actions.setStuff(foo, bar)),
updateThings: (a, b, c) => dispatch(actions.updateThings(a, b, c))
});After (with dispatchPassThrough)
import passThrough from 'dispatch-pass-through';
const mapDispatchToProps = dispatch => ({
setStuff: passThrough(dispatch, actions.setStuff),
updateThings: passThrough(dispatch, actions.updateThings)
});NOTE: THIS UTILITY MIGHT SEEM OUTRAGEOUSLY MINOR / SILLY...BECAUSE IT IS
Installation
$ yarn add dispatch-pass-throughor
$ npm install dispatch-pass-through --save