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;
}