i want to get the product stock and use it on detail but i have a problem
i have a fucntion like this.
async function getStock(productId, erp_code) {
let itemsStock;
await fetch(`${GET_STOCK}${productId}`, requestOptions)
.then(response => response.json())
.then(result => itemsStock = result[erp_code][0].LotQTY)
.catch(error => console.log('error', error));
console.log(itemsStock); i cant console.log the data
return itemsStock;
}
but in return i get a promise but that's not what i want.
i mean i get the data i need in function but i cant use it out of function
thats kinda annoying
PromiseĀ {_U: 0, _V: 0, _W: null, _X: null}
how can i fix this?