Current Behavior:
我试图通过打开视图来更新从服务器获取的列表.当我这样做时,onRefresh不会启动.
我已经在setState函数的回调中设置了GET请求,但这似乎没有任何作用.
Expected Behavior:
打开视图调用onRefresh函数.
代码:
...
constructor(props) {
super(props);
this.state = {
stories: [],
isFetching: false,
};
}
componentDidMount() { this.fetchData() }
onRefresh() {
this.setState({ isFetching: true }, function() { this.fetchData() });
}
fetchData() {
var that = this;
axios.get('http://192.168.0.13:3000/api/story/get/by/geo')
.then((res) => {
that.setState({ stories: res.data, isFetching: false });
that.props.dispatch(StoryActions.setStories(res.data))
})
}
render() {
return (
<ScrollView>
<FlatList
onRefresh={() => this.onRefresh()}
refreshing={this.state.isFetching}
data={this.state.stories}
keyExtractor={(item, index) => item.id}
renderItem={({item}) => (<StoryFeed story={item} id={item.id} /> )}
/>
</ScrollView>
)
}
Version Information
react 本机:0.45.0
node :7.4.0