0

I am trying to return a value that updates as data loads from a database.

However, when I fetch my data using async-await, my function returns a Promise, not the end value. When I check what's being returned, I get a value, but it does not seem to be returned.

 const fetchGameItems = async (items) => {
    try {
      let gameItems = await items
      console.log(gameItems)
      return await gameItems
    } catch (err) {
      console.error(err)
    }
  }

console.log(fetchGameItems(useLoadSpecficRecords(today).games.length))

// Logs
Promise {<pending>} // (From the console.log below the function declaration) 
2 // (from the fetchItems function)

useLoadSpecficRecords is a custom hook that loads data.

Tyler Morales
  • 882
  • 8
  • 24
  • 1
    Does this answer your question? [Async function returning promise, instead of value](https://stackoverflow.com/questions/51338277/async-function-returning-promise-instead-of-value) – TBA Oct 23 '21 at 04:28

0 Answers0