Я что то забыл что реакту нужно перерисовывать компонент, видимо рисовал он не сразу потому length таки оставалось 0
решил:
if (Array.isArray(productIdentifiersFromStorage)) {
const asyncFun = async () => {
const resultArray = [];
for (let p of productIdentifiersFromStorage) {
try {
const response = await getCategory(p.PurchasedCategoryId);
if (response.status === 200) {
const category = {
...response.data,
numberOfPurchases: p.NumberOfPurchases,
};
resultArray.push(category);
}
} catch (error) {
console.error(error);
}
}
setCategories([...resultArray]);
};
asyncFun();
} else {
console.error("No products");
}
}, []);