Skip to content

Instantly share code, notes, and snippets.

@basekays
Created October 1, 2018 22:12
Show Gist options
  • Save basekays/095ca2b131a7ff68ffa83b3110f5253c to your computer and use it in GitHub Desktop.
Save basekays/095ca2b131a7ff68ffa83b3110f5253c to your computer and use it in GitHub Desktop.
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