美文网首页
解决flatlist上拉加载更多onReachEnd多次执行的b

解决flatlist上拉加载更多onReachEnd多次执行的b

作者: 壹点微尘 | 来源:发表于2017-08-16 10:27 被阅读449次

flatlist上拉加载更多时,发现onReachEnd这个函数会被多次执行,这样就会导致数据源数据重复的问题

解决办法:
设置请求标志变量

代码如下:

constructor() {
  this.isLoadingMore = false;
}

loadMore() {
  if (this.isLoadingMore) {
    return;
  }
  this.isLoadingMore = true;

  fetch('https://www.baidu.com').then((res)=>{
    this.isLoadingMore = false;
  }).catch((e) => {
    this.isLoadingMore = false;
  })
}

render() {
  return (
    ...
    onReachEnd={() => this.loadMore()}
    ...
  );
}

相关文章

网友评论

      本文标题:解决flatlist上拉加载更多onReachEnd多次执行的b

      本文链接:https://www.haomeiwen.com/subject/nkzbrxtx.html