I am working on the backend of my React Native project with Firebase. I want to retrieve records from the database and render a flat ist from an array. I tried to make an array, but outside the function, it is empty again...
Here is my code:
var brand_list = [] // the list
//retrieve record from firebase database
firebase.firestore().collection('Brand').get().then((querySnapshot) => {
querySnapshot.forEach(snapshot => {
let data = snapshot.data();
brand_list.push(data);
})
console.log(brand_list) // contains the records
})
console.log(brand_list) // empty again
What is a possible fix for this, so I can nicely render my flatlist?