dispatch-pass-through

1.0.1 • Public • Published

CircleCI Coverage Status

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-through

or

$ npm install dispatch-pass-through --save

Readme

Keywords

none

Package Sidebar

Install

npm i dispatch-pass-through

Weekly Downloads

5

Version

1.0.1

License

MIT

Unpacked Size

156 kB

Total Files

9

Last publish

Collaborators

  • schne324