繁体   English   中英

如何使用导航事件重新加载反应原生

[英]How use navigation event to reload in react native

我有 homeScreen,这个屏幕有 useEffect 和数据过滤。 主页屏幕到配置文件屏幕和配置文件屏幕中的数据更新并返回主屏幕。 此更新的数据需要显示在主屏幕中。 我想知道导航事件焦点可以重新加载这个主屏幕吗? 怎么能做到这一点

 useEffect(()=>{

     let unsub;

     const fetchCard = async ()=>{
            
      // // user
           const uRef = query(doc(db,'users',user.uid))
           const udata = await getDoc(uRef)
          .then((snapshot)=>snapshot.data())

      //     console.log(udata.age)
         
      // //users

      //     const usRef = query(collection(db,'users'))
      //     const usdata =await getDocs(usRef)
      //     .then((snapshot)=>snapshot.docs.map(doc=>({
      //       id:doc.id,
      //       ...doc.data()
      //     })))

      //     console.log(usdata[0].age)


      const swipeRef = collection(db,'users',user.uid,'swipes')
      const myswipeid = await getDocs(swipeRef)
      .then((snapshot)=>snapshot.docs.map(doc=>doc.id))
      
     
      const swipeuserId = myswipeid.length>0?myswipeid :['test'];
     
 
  
      unsub = onSnapshot(query(collection(db,'users'),where('gender','==',udata.interestIn),where("id","not-in",[...swipeuserId])),
            snapshot=>{
                    setProfiles(
                      snapshot.docs
                     
                      .map(doc=>({
                        id :doc.id,
                        ...doc.data()
                      })
                     
                     )
                    )
                  }
      )
     }
     fetchCard()
     return unsub
  },[setProfiles])
   


如何通过导航重新加载此 useEffect。 有人可以给我看例子吗

如果您使用本机导航,则使用useFocusEffect https://reactnavigation.org/docs/function-after-focusing-screen/当您返回屏幕时调用此钩子(当前屏幕可见或聚焦时)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM