Last active
April 13, 2020 12:50
-
-
Save LarryKarani/9813c1c61d73bc52bc00b375ba5ca1d2 to your computer and use it in GitHub Desktop.
This file contains 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'; | |
import * as actions from './actions'; | |
export const getTodos = () => (dispatch) => { | |
dispatch(actions.apiRequest()); | |
axios.get('api/todos').then(res => { | |
dispatch(actions.getTodoSuccess(res.data)); | |
return res; | |
}) | |
.catch(error => { | |
dispatch(actions.getTodosFail(error)); | |
return error | |
}); | |
}; | |
export const addTodo = () => (dispatch) => { | |
dispatch(actions.apiRequest()); | |
axios.post('api/todos').then(res => { | |
dispatch(actions.addTodoSuccess(res.data)); | |
return res; | |
}) | |
.catch(error => { | |
dispatch(actions.addTodoFail(error)); | |
return error | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment