Skip to content

Instantly share code, notes, and snippets.

@muneneevans
Created November 4, 2017 10:06
Show Gist options
  • Save muneneevans/b86add65378c783c562d11a30061fa06 to your computer and use it in GitHub Desktop.
Save muneneevans/b86add65378c783c562d11a30061fa06 to your computer and use it in GitHub Desktop.
action creators. They will make redux dispatches using thunks
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