React Native FlatList Pagination to Load More Data dynamically – Infinite List

Here is an example of React Native FlatList Pagination to Load More Data dynamically – Infinite List. In this example, we will make a FlatList in which we will load the data in the form of pagination on a Click of a button.

For those who don’t know what is pagination?

Let’s take a case where you can simply imagine what if Facebook loads all the Facebook posts from the Facebook database on your Facebook wall? Doesn’t it sound nasty? It will take hundreds of hours even more than that so what is the best way to load the data?  Simply paging. When you open the Facebook they just show you 10-20 post and while you scroll the Facebook they load next 10-20 posts in background. That is what the paging is.

In our example,

  1. We are loading the first 10 posts from the web API call in componentDidMount.
  2. We have added load more button on the footer of the list.
  3. While clicking on the Load More Button we call the Web API again to get the next 10 posts.

We are using a variable offset to manage the index on upcoming Data. We will increase the offset by 1 after the successful call of the web API so that when we call the web API next time we will get the next dataset. So let’s get started with the example.

To Make a React Native App

Getting started with React Native will help you to know more about the way you can make a React Native project. We are going to use react-native init to make our React Native App.

Assuming that you have node installed, you can use npm to install the react-native-cli command line utility.
Open the terminal and go to the workspace and run Run the following commands to create a new React Native project This will make a project structure with an index file named App.js in your project directory.

Open App.js in any code editor and the Replace the code with the following code.

App.js

To Run the React Native App

Open the terminal again and jump into your project using. To run the project on an Android Virtual Device or on real debugging device or on the iOS Simulator by running

After Clicking on Load More It will load the data with the loader in Button

That was the React Native FlatList with Pagination to Load More Data dynamically. If you have any doubt or you want to share something about the topic you can comment below or contact us here. There will be more posts coming soon. Stay tuned!

Hope you liked it. 🙂

How useful was this post?

Click on a star to rate us!

Average rating / 5. Vote count:

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

About Snehal Agrawal

#SelfLearner #MobileAppDeveloper #TechnologyMiner #OpenSourceLover thats enough to describe me..

View all posts by Snehal Agrawal →

One Comment on “React Native FlatList Pagination to Load More Data dynamically – Infinite List”

  1. I am trying to do pagination with ActivityIndicator in react native but this functionality is not working properly.
    So please can you tell me about this.
    Thank You

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.