Last active
September 4, 2018 10:56
-
-
Save abachuk/395464e1f8dc5dc0623b1601da9f46fa 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
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