React-Native TypeError:未定义不是函数(在'... this.state.feeds.map ...'附近)

时间:2019-09-11 16:19:10

标签: react-native

我正在尝试在我的应用程序屏幕上显示来自URL的新闻提要。我已经为此组件(解析器)制作了一个组件,并将其导入到我的master.js文件中。

我正在使用 axios 从网址中获取数据。

我在从教程中学习时编写了这段代码,该代码在视频中有效,但对我无效。

在编译时,应用程序显示错误 TypeError:未定义不是函数(在'... this.state.feeds.map ...'附近)

我在跑步
博览会:3.0.1
react-native-cli:2.0.1
react-native:0.57.1​​
npm:6.11.3

获取数据的组件的代码为:

constructor(){
    super();
    this.state = {
        feeds: []
    }
}

componentWillMount(){
    axios.get('https://cointelegraph.com/rss')
      .then(response => this.setState({ feeds: response.data }));
}

renderFeeds = () => {
    return this.state.feeds.map(feed => <Text>{feed.title}</Text>);
}

render(){
    return (
        <View>
            {this.renderFeeds()}
        </View>
    );
}

显示的错误是: Error Image

TIA

1 个答案:

答案 0 :(得分:0)

map函数仅存在于数组上。 确保response.data是一个数组。