Skip to content

Instantly share code, notes, and snippets.

@LarryKarani
Last active April 13, 2020 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LarryKarani/9813c1c61d73bc52bc00b375ba5ca1d2 to your computer and use it in GitHub Desktop.
Save LarryKarani/9813c1c61d73bc52bc00b375ba5ca1d2 to your computer and use it in GitHub Desktop.
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