Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

hvolschenk/payload-action-creator

Repository files navigation

payload-action-creator

Build Status Coverage Status semantic-release

A very simple Redux payload action creator factory

Installation

payload-action-creator can be installed via npm:

$ npm i -S payload-action-creator

Usage

Create action creators by passing it the type of the action to create:

import action from 'payload-action-creator';

export const PRODUCTS_FETCHED = 'PRODUCTS_FETCHED';
export const productsFetched = action(PRODUCTS_FETCHED);

Now you can dispatch the action from a connected container in your application:

import { connect } from 'react-redux';
import { productsFetched } from './actions';
import Component from './component';

const mapDispatchToProps = dispatch => ({
  products: payload => dispatch(productsFetched(payload)),
});

export default connect(undefined, mapDispatchToProps)(Component);

The action creator will create an object like so:

{
  payload: thePayloadYouPassedIn,
  type: PRODUCTS_FETCHED,
}