Defining actions and action creators
Reducers accept an action
object that describes the action that is going to be performed and decides how to transform the state based on this action
object.
Actions are just plain objects and they have only one required property that needs to be present, the action-type. For instance:
const action = { type: 'INCREMENT_COUNTER', }
We can also provide additional properties as well. For instance:
const action = { type: 'INCREMENT_COUNTER', incrementBy: 2, }
Actions creators are just functions that return actions, for instance:
const increment = (incrementBy) => ({ type: 'INCREMENT_COUNTER', incrementBy, })
Getting ready
In this recipe, you will see how these simple Redux concepts can be applied with Array.prototype.reduce
to decide how data should be accumulated or reduced.
We won't need the Redux library yet for this purpose.
How to do it...
Build a small JavaScript application that will increase or decreased a counter based on the...