Is there any other use for an action other than to be dispatched, why don't actions dispatch when called?
Is this just a way to future proof an app for use with multiple stores?
This also creates a need for mapDispatchToProps which is usually completely boilerplate code to wrap actions with dispatch calls
It can often be summarized with this function that takes an object of actions and returns a mapDispatchToProps function
// mapActionsToDispatchProps.js
const mapActionsToDispatchProps = actions => {
return dispatch => (
actions.mapEntries(action => (
(...args) => dispatch(action(...args))
)
)
)
export default mapActionsToDispatchProps
Object.mapEntries example.
I see that last question about mapDispachToProps being mostly boilerplate can be avoided by passing an object of actions directly and connect will map them for me.
Note that an action is just a plain object with a type
field, while an action creator is a function that returns an action object.
The naming here is because Redux is originally an implementation of the "Flux Architecture", and Flux defines "actions" as "simple objects with a type
field". The question of whether to name them "actions" or "events" was heavily debated, and the conclusion was to keep using the Flux terminology since that's what existing Flux users would be most familiar with.
Now, of course, no one remembers that other Flux libraries existed, and many people assume that the term "action" was invented by the Redux team at some point.
For historical details, see the discussions in the following Redux issues:
And yes, we strongly encourage that folks use the "object shorthand" form of mapDispatch
.