0

I have problem with loading my data from Firebase. When I load my page for first the time it doesn't load the data from firebase. When I refresh the page its always getting and displaying right data. I guess that my function needs to use firebase or js promises to resolve the problem. Does anybody could point me in right direction ? Thanks

Here is the my function.

function QueryFirebase() {
    var list = [];
    //access connection object
    const firebase = require('../firebase.js');

    let ref = firebase.database().ref('messages');
    var usersRef = ref.child('message');
    usersRef.on('child_added', function (snap) {
        var m = snap.val();
        list.push(m);
    });

    list.reverse();
    return list;
}
KENdi
  • 7,576
  • 2
  • 16
  • 31
  • `usersRef.on` returns a promise. You need to put your logic in the promise return. – camden_kid Sep 28 '17 at 10:56
  • 1
    @camden_kid it returns a function, not a promise: [docs](https://firebase.google.com/docs/reference/js/firebase.database.Reference#on) – alexmac Sep 28 '17 at 11:31

0 Answers0