I make a async function to get offers, and add to array with another array. But the offers array are looking empty in console, but when I click shows the itens.
The products are comming that's isn't the problem. The problem is that I can't add the arrayOffers
to itemsArray
.
OBS: the forEach is from p-interation
lib.
this is my code.
useEffect(() => {
if (auth && auth._id) {
const fetchUserVisitedProducts = async (id) => {
const user = await getPublicUserRequest(id);
let array = [];
forEach(user.offers_visited, async (id) => {
const offers = await getOfferRequest(id)
array.push(offers)
});
const arrayOffers = array;
console.log(arrayOffers)
const itemsArray = [ ...user.barbadas_visited, ...arrayOffers]
console.log(itemsArray)
}
fetchUserVisitedProducts(auth._id)
}
},[auth])
In the image, I see one array with 4 objects, but looks empty. And another array that is correct.