Mehedi Hassan Piash [Sr. Software Engineer]

December 12, 2019

FlatList Pagination Two Times Call Problem in React-Native

December 12, 2019 Posted by Piash No comments
There is a common problem while working with FlatList pagination. It calls two times with out any reason. We can solve it in different ways.But I have a very effect way which is worked for me.

Try to implement onMomentumScrollBegin on FlatList :
constructor(props) {
    super(props);
    this.onEndReachedCalledDuringMomentum = true;
}
<FlatList
    ...
    onEndReached={this.onEndReached.bind(this)}
    onEndReachedThreshold={0.5}
    onMomentumScrollBegin={() => { this.onEndReachedCalledDuringMomentum = false; }}
/>
and modify your onEndReached
onEndReached = ({ distanceFromEnd }) => {
    if(!this.onEndReachedCalledDuringMomentum){
        this.fetchData();
        this.onEndReachedCalledDuringMomentum = true;
    }
}