0

I am fetching data from an API to get the number of likes. this is the function to get all the data

`

const getLikes = async () => {
 const response = await fetch(`https://us-central1-involvement-api.cloudfunctions.net/capstoneApi/apps/${apiKey}/likes`)
 const likeData = await response.json();
 return likeData;
}

`then I want to store info in a variable so I wrote this other function

`

const likesObj = async ()=> {
  const getLike = await getLikes()
  return getLike;
  
}

`

when I console.log the const getLike it does print an Array of objects with every item and the number of likes it has. but when I return getLikes it returns a promise, how can I return the result and not the promise

I tried with .then() but I get the same result

  • `likesObj` is useless, because all it does is effectively `return await`, which is always useless (at least if no error handling is done). See [Difference between `return await promise` and `return promise`](/q/38708550/4642212). You have to _use_ `getLike`. And you have to do so inside the `async` function, or use modules and use [top-level `await`](//developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/await#top_level_await). – Sebastian Simon Nov 24 '22 at 18:55
  • simply use the promises if you want to return something asynchronously – aashir khan Nov 24 '22 at 18:57
  • `return await` isn't always useless. It's often useful for error handling inside a `try/catch`. But yeah, async promises always return promises by definition. No way around it. – CollinD Nov 24 '22 at 18:57

0 Answers0