schne324 / dispatch-pass-through

Tiny utility for passing arguments through in a react-redux mapDispatchToProps call

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

Tiny utility for passing arguments through in a react-redux mapDispatchToProps call

License:MIT License


Languages

Language:JavaScript 100.0%