type
value to use, and an action creator to generate actions of that type.createAction
helper, described in this guide, helps you reduce the noise while keeping the benefits. Here is the equivalent code using createAction
:createAction
and its capabilities in more detail.createAction
helper allows you define an action with a single declaration, minimizing boilerplate and room for error. Given an action type value, it returns a matching action creator.type
property on the returned action creator (e.g., increment.type
in the example above). This means you don't need to define a separate action type constant.matches()
method that compares its type
with that of a given actions, and returns true if they match. In TypeScript, this method is defined as a [type predicate][ts-type-predicate], so that the compiler can narrow the type of the action in code sections where matches()
is true:createAction
action creator in place of an action type value. For instance, onAction
(described in the Reducers guide) lets you specify the action type by directly passing increment
instead of increment.type
or 'counter/increment'
. This is especially beneficial if you use TypeScript, where the action creator's static type is used for automatic type inference.createAction
produce basic actions with nothing more than a type
. But this can be changed, as described in the next section.createAction
allows you to generate payload action creators. These take a single argument and attach it to the returned action as payload
..withPayload()
on an action creator returned by createAction
: