Implementing actions and action creators
In the first chapter, we learned how important actions are in Redux. Only actions can change the state of your application.
Note
Actions in Redux are valid if they have a type
property. The rest of the object structure is totally up to you. If you prefer using a standard structure, check out https://github.com/acdlite/flux-standard-action.
Redux actions are simple JavaScript objects with a type
property, which specifies the name of the action.
Let's define a simple action, in the src/index.js
file:
const createPost = { type: 'CREATE_POST', user: 'dan', text: 'New post' } console.log(createPost)
Now, save the file. Webpack should automatically refresh the page after modifying and saving a source file (such as src/index.js
).
Separating action types
As we have learned in Chapter 1, Why Redux? reducers use the type
property to check which action happened. That works fine, but there is a little problem with the value—it's a string. With string values, it is very...