React native 反应双重执行

React native 反应双重执行,react-native,React Native,我正在使用scrollview上的无限滚动,为此,我使用Refrescontrol和该功能: handleOnScroll(e){ let yOffset = e.nativeEvent.contentOffset.y; if (this.state.hWall && this.state.hWall - this.state.hScreen - yOffset <= 0 && !this.state.isRefres

我正在使用scrollview上的无限滚动,为此,我使用Refrescontrol和该功能:

    handleOnScroll(e){
        let yOffset = e.nativeEvent.contentOffset.y;
        if (this.state.hWall && this.state.hWall - this.state.hScreen - yOffset <= 0 && !this.state.isRefreshing){
            this.setState({ isRefreshing : true }, () => this.getPosts('more') );
        }
    }
handleOnScroll(e){
设yOffset=e.nativeEvent.contentOffset.y;
if(this.state.hWall&&this.state.hWall-this.state.hsscreen-yOffset this.getPosts('more');
}
}

现在的问题是我总是有两个
this.getPosts('more')
调用,如何在getPosts操作完成之前防止双重调用?

问题是setState是异步的。尝试使用
this.isRefresing
来控制是否正在进行重设

handleOnScroll(e){
  let yOffset = e.nativeEvent.contentOffset.y;
  if (this.state.hWall && this.state.hWall - this.state.hScreen - yOffset <= 0 && !this.isRefreshing){
    this.isRefresing = true; //this is syncronous
    //setState is still required if you want to update your UI
    this.setState({ isRefreshing : true }, () => this.getPosts('more') );
  }
}
handleOnScroll(e){
设yOffset=e.nativeEvent.contentOffset.y;
if(this.state.hWall&&this.state.hWall-this.state.hsscreen-yOffset this.getPosts('more');
}
}
此外,如果您用滚动视图交换平面列表,则可以在列表即将结束时使用
onEndReached
回调获取更多数据