I would like to fetch data from a URL that is stored in the Firebase database and display the data in my React Native app, I tried some tutorials on Promies and Async/Await but I can't seem to apply them to my problem here is my code:
listenForItems(itemsRef) {
itemsRef.on('value', (snap) => {
var items = [];
snap.forEach((child) => {
items.push({
url: child.val().url,
_key: child.key
});
});
this.setState({ urls: items });
//this.fetchData(); calling fetch here causes duplicate data
});
this.fetchData(); // calling fetch here does not display data
}
How can I asynchronously display the data using promises or async/await?