Skip to content

Instantly share code, notes, and snippets.

@abachuk
Last active September 4, 2018 10:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abachuk/395464e1f8dc5dc0623b1601da9f46fa to your computer and use it in GitHub Desktop.
Save abachuk/395464e1f8dc5dc0623b1601da9f46fa to your computer and use it in GitHub Desktop.
import axios from 'axios';
export const GET_POSTS_START = 'GET_POSTS_START';
export const GET_POSTS_SUCCESS = 'GET_POSTS_SUCCESS';
export const GET_POSTS_FAIL = 'GET_POSTS_FAIL';
const getPostsStart = () => ({
type: GET_POSTS_START,
});
const getPostsSuccess = posts => ({
type: GET_POSTS_SUCCESS,
posts,
});
const getPostsFail = error => ({
type: GET_POSTS_FAIL,
error,
});
export const getPosts = () => (dispatch) => {
dispatch(getPostsStart());
return axios({
url: `/api/posts`,
method: 'get',
})
.then(res => {
dispatch(getPostsSuccess(res.data));
return res;
})
.catch(error => {
dispatch(getPostsFail(error));
return error;
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment