Actions

As we saw at the beginning of the chapter, an action is nothing but a plain JavaScript object that describes what has happened. To change the state is to emit an action that describes what has happened. Also, for store, actions are only the source of truth or information.

Here's an example action creator.

Each action type should be defined as a constant:

const fetchSeats = rows => ({
type: GET_SEATS,
rows
})

The type of an action describes the kind of the action that has occurred. If your application is large enough, you may separate out the action types as string constants to a separate module/file and use it in actions.

Now, you might be having a question—what should be the structure of my action ? We
have here type and then have directly added rows. The answer to your question is that except the type, you can have any structure of your action. However, there is a standard for defining an action.

An action must be a JavaScript Object and must have a type property. Also, an action may have an error or payload property. The payload property can be any type of value. In the preceding example, rows represent a payload.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset