Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

177
Vistas
Trying to loop through firebase and display each object as a card React

My data is structured like so [1]: https://i.stack.imgur.com/dWsr3.png

I am trying to loop through the database and put the data from each card into props for my ProductCard> component. It takes in values as I've been racking my brain with this and googling constantly, but this is my best attempt.

const db = getDatabase();
const dbRef = ref(db, 'products');
onValue(dbRef, (snapshot) => {
    snapshot.forEach((childSnapshot) => {
      return (
          <ProductCard title={childSnapshot.val().prod_title} />
      )
    });
  }, {
    onlyOnce: true
  });

I'm very much a noob with react so I appreciate any advice!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Use map function instead of forEach to return an array of JSX elements, and then do something with this elements array (not sure what, since your snippet is too small):

const elements = snapshot.map((childSnapshot) => {
  return (
      <ProductCard title={childSnapshot.val().prod_title} />
  )
});
// do something with elements array here or maybe just return it
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda