Skip to content

Instantly share code, notes, and snippets.

@viknedus
Created August 30, 2021 09:42
Show Gist options
  • Save viknedus/a4b1466eab7813eff950009b352f7ce4 to your computer and use it in GitHub Desktop.
Save viknedus/a4b1466eab7813eff950009b352f7ce4 to your computer and use it in GitHub Desktop.
Two pieces of JS code with and without Async, Await
export const getSingleTaskAction = id => {
return async dispatch => {
dispatch({ type: types.TASKS_START });
try {
const res = await codeClanApi
.get(`/tasks/${id}`);
dispatch({ type: types.GET_TASK, payload: res.data });
} catch (err) {
const error_msg = err.response
? err.response.data.message
: 'An error occurred';
dispatch({
type: types.TASKS_FAILURE,
payload: error_msg,
});
}
};
};
export const getSingleTaskAction = id => {
return dispatch => {
dispatch({ type: types.TASKS_START });
return codeClanApi
.get(`/tasks/${id}`)
.then(res => {
dispatch({ type: types.GET_TASK, payload: res.data });
// history.push(`/dashboard`)
})
.catch(err => {
const error_msg = err.response
? err.response.data.message
: 'An error occurred';
dispatch({
type: types.TASKS_FAILURE,
payload: error_msg,
});
});
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment