当前行为:
我正在尝试通过拉起视图来更新从服务器获取的列表。当我这样做时,onRefresh 不会触发。
我在 setState 函数的回调中设置了 GET 请求,但这似乎没有做任何事情。
预期行为:
拉起视图调用 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>
)
}
版本信息
反应原生:0.45.0
节点:7.4.0