A very simple Redux payload action creator factory
payload-action-creator
can be installed via npm:
$ npm i -S payload-action-creator
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,
}