Let's think about which actions we need to dispatch while making a request to get all posts from the backend:
- FETCH_POSTS_REQUEST: We dispatch this action immediately when the request begins. The following action can be used to, for example, show a loading indicator while a request is in progress:
{ type: 'FETCH_POSTS_REQUEST' }
- FETCH_POSTS_SUCCESS: This action is dispatched once the server responds to our request, returning all posts. This action contains an array of posts, which we will store in our application state through a reducer:
{ type: 'FETCH_POSTS_SUCCESS', posts: [] }
- FETCH_POSTS_FAILURE: If the request fails or the server returns an error status code, we dispatch the following action and handle the error ...