0

I'm building a news reader app using React Native. However when I try to fetch the feed from a url it shows this error:

I'm running the latest version of React Native and Nodejs. This shows when i run run-android:

enter image description here

This is my News.js:

class News extends Component {
    state = {
        articles: [],
        refreshing: true
    };

    componentDidMount = () => {
        this.fetchNews();
    };

    fetchNews = () => {
        getHomeNews()
            .then(articles => {
                this.setState({ articles, refreshing: false });
            })
            .catch(() => this.setState({ refreshing: false }));
    };

    handleRefresh = () => {
        this.setState({ refreshing: true }, () => this.fetchNews());
    };

    render() {
        console.log(this.state.articles);
        return (
            <FlatList
                data={this.state.articles}
                renderItem={({ item }) => <Article article={item} />}
                keyExtractor={item => item.url}
                refreshing={this.state.refreshing}
                onRefresh={this.handleRefresh}
            />
        );
    }
}

And this is my fetchNews.js:

const url = ` URL here`;

export async function getHomeNews() {
    let result = await fetch(url).then(response => response.json());

    return result.articles;
}
 
Can anyone show me where I messed up? Thank you for your time.

quachhengtony
  • 125
  • 4
  • 17

0 Answers0