Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I display data from Firebase database?

In the application, you can add your bank to the Firebase database. When you click on the "Add Bank" button, the bank is saved to the database. I need to display cards with added banks on the screen. How can i do this? Now I am reading data from the database and it comes in the form of an object:

enter image description here

Code for read data:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

const getBanksFunc = () => {
  const bankRef = ref(database, "banks/");
  onValue(bankRef, (snapshot) => {
    const data = snapshot.val();
  });
};

>Solution :

Firebase’s documentation covers this:

https://firebase.google.com/docs/database/web/read-and-write

import { getDatabase, ref, onValue} from "firebase/database";

const db = getDatabase();
const starCountRef = ref(db, 'posts/' + postId + '/starCount');
onValue(starCountRef, (snapshot) => {
  const data = snapshot.val();
  updateStarCount(postElement, data);
});

In your case, a for .. in loop could work:

for(let key in data) {
    const { bankName, interestRate, loanTerm, maximumLoan, minimumDownPayment } = data[key];
    ... do whatever you need
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading