Making action creators and dispatching actions
Actions are the most crucial pieces of Redux; they are responsible for triggering state updates in our Redux Store. In this recipe, we are going to display the top 100 cryptocurrencies listed on http://www.coinmarketcap.com using their public API.
Getting ready
For this recipe, we need to install Axios (a promise-based HTTP client for the browser and Node.js) and Redux Thunk (a thunk is a function that wraps an expression to delay its evaluation):
npm install axios redux-thunk
How to do it...
We are going to use the same code we created in the last recipe (Repository: /Chapter05/Recipe1/store
) and add some modifications:
- First, we need to create new folders:
src/actions
,src/reducers
,src/components/Coins
, andsrc/shared/utils
.
- The first file we need to create is
src/actions/actionTypes.js
, where we need to add our constants for our actions:
export const FETCH_COINS_REQUEST = 'FETCH_COINS_REQUEST'; export const FETCH_COINS_SUCCESS = 'FETCH_COINS_SUCCESS...