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

175
Views
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 answers
Answer question

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 Report
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!