Created
November 4, 2017 10:06
-
-
Save muneneevans/b86add65378c783c562d11a30061fa06 to your computer and use it in GitHub Desktop.
action creators. They will make redux dispatches using thunks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as types from "./actionTypes" | |
import JsonPlaceHolderService from "./service" | |
export function fetchPosts(){ | |
return function(dispatch, getState){ | |
//dispatch an action to show the starte | |
dispatch({type: types.POSTS_REQUESTED}) | |
return JsonPlaceHolderService.getPosts() | |
.then(posts =>{ | |
dispatch({ | |
type: types.POSTS_RECEIVED, | |
payload : posts | |
}) | |
}) | |
.catch(error =>{ | |
throw(error) | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment