I am fairly new to React Native, so bear with me.
I use the following code to get RSS items form a feed.
fetch("https://feed.podbean.com/omroepvoeren/feed.xml")
.then((response) => response.text())
.then((responseData) => rssParser.parse(responseData))
.then((rss) => {
for (var item of rss.items) {
console.log(item.title);
}
});
This seems to work. All titles are shown in the console. But when I change the code to this:
var listOfTitles = [];
fetch("https://feed.podbean.com/omroepvoeren/feed.xml")
.then((response) => response.text())
.then((responseData) => rssParser.parse(responseData))
.then((rss) => {
for (var item of rss.items) {
listOfTitles.push(
<View>
<Text>{item.title}</Text>
</View>
);
}
});
console.log(listOfTitles);
The array remains empty. Array []
What is going wrong here?