Tengo homeScreen, esta pantalla tiene useEffect y tiene filtrado de datos. Pantalla de inicio a la pantalla de perfil y actualización de datos en la pantalla de perfil y regreso a la pantalla de inicio. estos datos actualizados deben mostrarse en la pantalla de inicio. Quiero saber si el enfoque del evento de navegación puede volver a cargar esta pantalla de inicio. como se puede hacer esto
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])cómo puede recargar este useEffect navegando hacia atrás. alguien me puede mostrar un ejemplo
Si usa la navegación nativa de reacción, use useFocusEffect https://reactnavigation.org/docs/function-after-focusing-screen/ esta llamada de enlace cuando regrese a la pantalla (cuando la pantalla actual está visible o enfocada)
import { useFocusEffect } from '@react-navigation/native'; useFocusEffect(()=>{ 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},[])