I am following along with a netflix clone project off of youtube that was put out about 6mo ago. Since the tutorial came out I believe firebase/firestore and react have released newer versions of themselves which seems to be causing the tutorial code to break. Here is what the tutorial wants us to use:
```import React, { useState, useEffect } from 'react';
import db from "../firebase";
import './PlansScreen.css';
function PlansScreen() {
const [products, setProducts] = useState([]);
useEffect(() => {
db.collection("products")
.where("active", "==", true)
.get()
.then(querySnapshot) => {
const products = {};
querySnapshot.forEach(async (productDoc) => {
products[productDoc.id] = productDoc.data();
const priceSnap = await productDoc.ref.collection
("prices").get();
priceSnap.docs.forEach((price) => {
products[productDoc.id].prices = {
priceId: price.id,
priceData: price.data(),
};
});
});
setProducts(products);
});
}, []);
console.log(products)
return (
<div className='plansScreen'>
</div>
)
}
export default PlansScreen```
What this code block is supposed to do is go into the collection named Products, create Product objects containing each Product Document's data, then go into each Product Document's subcollection called Prices, grab the data from each corresponding Price document, and add the data to to its Product object. Then the Product objects are logged to the console. The codeblock above does work unfortunately. HOWEVER I was able to refactor the code somewhat to be current with firebase/firestore and REACT.js which does do some of what it needs to. Here is my refactor:
```import React, { useState, useEffect } from 'react';
import db, { collection, getDocs } from "../firebase";
import './PlansScreen.css';
function PlansScreen() {
const [products, setProducts] = useState([]);
useEffect(() => {
const get = async () => {
const prodRef = collection(db, 'products');
const prodSnap = await getDocs(prodRef);
prodSnap.forEach(async (prodDoc) => {
products[prodDoc.id] = prodDoc.data();
});
setProducts(products);
};
get();
}, [products]);
console.log(products)
return (
<div className='plansScreen'>
</div>
)
}
export default PlansScreen```
as you can see I had to refactor the way I was importing firebase and some firebase tools. My refactored code block does log each Product object in the console but it does not include the data from the prices subcollection. That is my currrent issue. I have tried many things but cannot seem to figure out how to access the subcollection to grab data during the process of creating the product objects. Hopefully someone can show me how to do it because all the stackoverflow answers are from awhile ago and those methods don't seem to work anymore.