createActionand its capabilities in more detail.
createActionhelper 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.
typeproperty on the returned action creator (e.g.,
increment.typein the example above). This means you don't need to define a separate action type constant.
matches()method that compares its
typewith 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
createActionaction 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
'counter/increment'. This is especially beneficial if you use TypeScript, where the action creator's static type is used for automatic type inference.
createActionproduce basic actions with nothing more than a
type. But this can be changed, as described in the next section.
createActionallows you to generate payload action creators. These take a single argument and attach it to the returned action as
.withPayload()on an action creator returned by