mobile menu icon

Types of actions in a Redux App

Published by Carlos Blé on 05/04/2017

React, Redux, JavaScript


In the previous post there was a bunch of tests but not the code that make them pass. In the way we’re building apps with Redux, there are different kinds of actions and creators injected in the components. We usually talk just about actions without distinction. These are the various kinds:

There are situations where the store’s state is not going to change, so there is no need for a reducer. If I just want to send some data to the server, I don’t need the Redux machinery. I just post data from the component to the server through my non-redux-related action. In the previous post about the factory I explained how to map actions to the component. Action creators connected to Redux must be dispatched whereas non-redux actions must not.

Asynchronous action creators are needed when data needs to be fetched from the server or sent to the server and passed through the reducers thus changing the store’s state.

Populating store with data from server:

Processing data and changing the state before sending it to the server:

Redux-thunk middleware provides two arguments to the function, dispatch and getState. The first one triggers the reducers process and the second gets the current state from the store.

Action creators are just functions, they can be easily tested in isolation although we usually test them in integration as described in previous posts.

Volver a posts