Good afternoon StackOverflowers I'm working on building a RssFeeder app in order to work on my React Native skills but somehow ran into a problem which I wanted to fix now, as I try to render my objects which I get from an outside API called newsAPI and I try to show them into a flatList which for some reason doesn't work as I hope; here is my HomeScreen part for the flatList:
return (
<View>
<Text>We have found {articles?.length} articles</Text>
<FlatList
data={articles}
showsHorizontalScrollIndicator={false}
horizontal
scrollEnabled
keyExtractor={(articles) => articles?.name}
extraData={articles}
renderItem={({ item }) => {
return (
<TouchableOpacity onPress={() => navigation.navigate("Detail")}>
<DetailScreen result={item} />
</TouchableOpacity>
);
}}
></FlatList>
I'm pretty sure that API works properly cause the first line which shows the length of the articles shows the exact number, in addition, I added a Text component after <DetailScreen result={item} /> and it shows me Text components 10 times, so I wonder what is the problem with the code.
result in the <DetailScreen result={item} /> is a madeup prop for my second screen called 'DetailScreen' to carry all the data from Home to DetailScreen.
Also, this is what DetailScreen looks like at the moment.
import React from "react";
import { Text, View, StyleSheet } from "react-native";
import HomeScreen from "./HomeScreen";
const DetailScreen = (result) => {
return (
<View>
<Text>{result.title}</Text>
</View>
);
};
const styles = StyleSheet.create({});
export default DetailScreen;
This is a sample from the API:
{ "source": { "id": "techcrunch", "name": "TechCrunch" }, "author": "Jonathan Shieber", "title": "How did Atlanta become a top breeding ground for billion-dollar startups in the Southeast?", "description": "Over the past five years, the Southeastern region, led by Atlanta, has gone from being “one of the best kept secrets” in tech, to a vibrant ecosystem teeming with a herd of the billion dollar tech businesses that are referred to in the investment world as “un…", "url": "https://techcrunch.com/2021/05/02/how-did-atlanta-become-a-top-breeding-ground-for-billion-dollar-startups-in-the-southeast/", "urlToImage": "https://techcrunch.com/wp-content/uploads/2018/06/GettyImages-467404053.jpg?w=600", "publishedAt": "2021-05-02T15:25:38Z", "content": "Over the past five years, the Southeastern region, led by Atlanta, has gone from being “one of the best kept secrets” in tech, to a vibrant ecosystem teeming with a herd of the billion dollar tech bu… [+18425 chars]" },