I was following a tutorial when I came across this bit of code:
export function fetchUserData () {
return axios.get('https://randomuser.me/api')
.then(res => {
return res;
})
.catch(err => {
console.error(err);
})
}
When this function is called with:
const getUserData = async () => {
let ud = await fetchUserData()
setUserData(ud);
console.log(ud);
}
I get the data I want but I am confused with how the first function works. If I remove return from return axios.get('https://randomuser.me/api')
it no longer works, and is parameter of the callback function of .then
always the return of the previous function?
I assume its because of some of javascript short hand I'm not aware of so could someone explain to me? Thank you.