0
  useEffect(() => {
    console.log('component mounted!')
    getLikedProduct()
  },[])
  async function getLikedProduct(){
    try{
      var snapshot = await firestore.collection("Likes").where("user","==",auth.currentUser.uid).where("timeStamp", ">", 1).orderBy("timeStamp","desc").get()
      snapshot.forEach(doc => {
        collectedProductId.push(doc.data().product)
      })
      setCollectedProductId(collectedProductId)
      collectedProductId.forEach(async doc2=>{
        var snapshot2 = await firestore.collection("Products").where("id","==",doc2).get()
        snapshot2.forEach(doc => {
          temp.push(doc.data());
          setCollectedProduct(temp);
        });
      })
    }
    catch(e){
      console.log(e)
    }
  }

this is my code and it does not render the data just i expected before I click touchable opacity of this page. Any clues or hints can I get to solve this problem?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
boriii
  • 87
  • 6
  • 2
    Every time you update collectedProductId, you should update the state, in this line you are adding new items collectedProductId.push(doc.data().product), but the state isn't updated, the same here collectedProduct.push(doc.data()) – lissettdm Dec 27 '20 at 21:26
  • That sounds a great answer @lissettdm . :) *edit*: Sorry, I didn't notice the question had been closed already. – Frank van Puffelen Dec 27 '20 at 21:48
  • what about this ? I have changed my code – boriii Dec 27 '20 at 22:09

0 Answers0