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

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多次执行的bug)