Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
¿Cómo puedo obtener datos de firebase para cada elemento en una Flatlist?

Tengo una lista plana que recibe eventIds como datos. En cada llamada de renderItem, quiero encontrar el objeto de evento correspondiente a cada eventId en firebase y representar estos datos. (Por ejemplo, título o imagen de este evento)

Esta es la función para obtener un solo evento de firestore basado en eventId:

 export async function getSingleEventDataFireStore(eventId) { const db = firebase.firestore(); const eventFirestoreDoc = db.collection("events").doc(eventId); const doc = await eventFirestoreDoc.get(); if (!doc.exists) { console.log("No such Event!"); } else { console.log("Event data fetched!"); return await doc.data(); } }

aquí es donde se muestra la lista plana:

 const EventScreen = () => { const [event, setEvent] = useState([]); const [eventFetched, setEventFetched] = useState(false); const eventIds = [{id:'1', eventId: 'jaelfmk130'}, {id:'2', eventId: '1jlk335n1'}] const renderItem = ({ item }) => { if (!eventFetched) { firestore.getSingleEventDataFireStore(item.eventId).then((eventItem) => { setEvent(eventItem); setEventFetched(true); }); } setEventFetched(false) return ( <View><Text>{event.title}</Text></View> ) } return ( <View> <FlatList data={eventIds} keyExtractor={(item) => item.id} renderItem={renderItem} /> </View> ) }

Esto termina en un bucle infinito, porque configuré eventFetched en falso nuevamente durante renderItem. De lo contrario, si elimino setEventFetched (falso), solo representa un elemento.

¿Cómo puedo establecer eventFetched en falso después de la representación de cada elemento sin terminar en un bucle?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!