Created
October 1, 2018 22:12
-
-
Save basekays/095ca2b131a7ff68ffa83b3110f5253c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
export const GET_PLACES = "DOUMI_NATIVE/GET_PLACES"; | |
export const GET_PLACES_SUCCESS = "DOUMI_NATIVE/GET_PLACES_SUCCESS"; | |
export const GET_PLACES_FAILURE = "DOUMI_NATIVE/GET_PLACES_FAILURE"; | |
export function getPlacesFailure(errors) { | |
return { | |
type: GET_PLACES_FAILURE, | |
errors, | |
} | |
} | |
export function getPlacesSuccess(places) { | |
return { | |
type: GET_PLACES_SUCCESS, | |
places, | |
} | |
} | |
export function getPlaces() { | |
return (dispatch) => { | |
dispatch({ type: GET_PLACES }); | |
fetch('http://localhost:3000/api/v1/places') | |
.then((response) => response.json()) | |
.then((data) => { | |
dispatch(getPlacesSuccess(data)); | |
}) | |
.catch((errors) => { | |
dispatch(getPlacesFailure(errors)); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment