Problem Description
I’m developing an e-commerce React application and have successfully uploaded product information and images to Firebase. However, I’m experiencing challenges retrieving and displaying both product content and associated images concurrently.
Current Implementation
const [products, setProducts] = useState([]);
const fetchProductCatalog = async () => {
const productCollection = collection(db, "inventory");
const productQuery = query(productCollection, orderBy("productId"));
await getDocs(productQuery)
.then((snapshot) => {
const productData = snapshot.docs.map((doc) => ({
...doc.data(),
productId: doc.data().productId,
title: doc.data().title,
summary: doc.data().summary
}));
setProducts(productData);
})
.catch((error) => {
console.error("Product retrieval failed", error);
});
};
Any suggestions on improving data retrieval efficiency would be greatly appreciated!