Created
August 30, 2021 09:42
-
-
Save viknedus/a4b1466eab7813eff950009b352f7ce4 to your computer and use it in GitHub Desktop.
Two pieces of JS code with and without Async, Await
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
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, | |
}); | |
} | |
}; | |
}; |
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
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