Skip to content

Instantly share code, notes, and snippets.

@itzsaga
Created July 6, 2017 05:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itzsaga/1cba5578104707b9b4431778f9ab6d86 to your computer and use it in GitHub Desktop.
Save itzsaga/1cba5578104707b9b4431778f9ab6d86 to your computer and use it in GitHub Desktop.
// fetch places
function fetchPlaces () {
return (dispatch) => {
dispatch({type: 'FETCH_PLACES'})
return fetch('http://localhost:3001/api/places')
.then(response => {
response.json()
.then(json => {
dispatch({type: 'RECEIVED_PLACES', payload: json})
})
})
.catch((err) => {
dispatch({type: 'FETCH_PLACES_ERROR', payload: err})
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment