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.