React-Native:setState doens更新render()

时间:2017-05-22 12:26:14

标签: reactjs view react-native refresh

渲染功能:

render() {
return (
  <ScrollView>
    <Image style={Styles.Logo} source={require('../img/Logo.png')} />
    <List>
        {this.state.feeds.map( feedData => {
            return <ListItem
                key={feedData.id}
                title={feedData.title}
                titleStyle={Styles.Title}
                subtitle={feedData.content}
                subtitleStyle={Styles.Subtitle}
            />
        })}
    </List>
  </ScrollView>
);
}

AppStateChange事件:

_handleAppStateChange = (nextAppState) => {
if (this.state.appState.match(/inactive|background/) && nextAppState === 'active') {
    console.log("App came in the foreground.");
    this.fetchFeeds();
}
this.setState({appState: nextAppState});
}

FetchFeeds:

fetchFeeds() {
Feeds.then(res => {
  this.setState({
    feeds: res
  })
}).catch(err => {
  console.log(err)
})
}

&#34;应用程序出现在前台&#34;由控制台记录。但是视图不会使用新信息(当前是一个简单的时间戳)进行更新,尽管反应文档说在更改状态时它将重新呈现。 (不幸的是,forceUpdate()也不适用于此)

0 个答案:

没有答案