DEV Community

Discussion on: "Synchronous" fetch with async/await

Collapse
 
archs profile image
Archs

your request function doesn't return the json result, only logs it. The function still returns a promise in my code, is it normal behavior? should the request function be sync when called as

const res = request()

?

Collapse
 
johnpaulada profile image
John Paul Ada • Edited

ahh the function wrapping that should also be async, so it should be like:

const useRequest = async () => {
  const res = await request()
}

useRequest()

given that you return the json instead of just logging it in the request() function.

Collapse
 
mindyzwan profile image
Mindy Zwanziger

Exactly what I needed to know too - thanks!