How to Add an IF (Condition) to onEndReached in React-Native?

Asked

Viewed 106 times

0

I have a flatList which loads 20 records at a time, when it arrives at the end of the list, the component onEndReached calls my method that carries over 20, and so loads up to bring everyone, however, when my records run out, it still tries to search, which decreases the performance of my App. I tried to add an IF to the onEndReached, but as it is inside a flatList I could not do it. someone has a solution for this?

Example of my Code:

<FlatList
        data={this.state.data}
        renderItem={({ item }) => (
          <ListItem
            title={item.conta}
            subtitle={item.saldo}

          />
        )}
        keyExtractor={(item) => {
          return item.id;
        }}
        onEndReached={this.makeRemoteRequest}
        onEndReachedThreshold={0.1}

      />

1 answer

0


You can use the if ternary in this case:

onEndReached={this.makeRemoteRequest == condição ? Se sim : Se não}

I hope I helped friend.

  • Show, it worked. Thanks for the help Maycon.

  • Friend if you can score the answer, I’ll be very grateful.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.