React-native Fetch GET request example with FlatList

techup.co.in

In this article we learn about React-native Fetch GET request example with FlatList, in this, we are going to display JSON array response in List,

as we know ListView component is deprecated so the best alternative is to use the React-native FlatList component it supports both vertical and horizontal dimension view, also support both Android and IOS device, it support Header and Footer support also we cannot use other libraries for pull to refresh it support pull to refresh, scroll loading, scroll to index, let’s take example

This is the basic syntax of FlatList:

This will display Tom and Jerry values of key name

To explain this in detail, we need to start with fetch call, to display data in FlatList

1. Add following imports

2. Fetch GET request

Create one method to call fetch API call and call this method componentDidMount() method of react-native this will call at app first-time start

Now our response JSON is as follows

To display these JSON data use FlatList as follows

before that, I suggest you install image loader library component by using the following command in the command line

After this, response data had successfully parse and saved this response in the state then use that list from the response object in FlatList component now we will be going to handle on click to do this we have to use the react-native TouchableOpacity onPress method its very simple create another method GetListItem and call this method as follows

activeOpacity props handle onPress opacity animation

let’s see whole js file code so that we can understand clearly

3. App.js

4. Output:

As we see in about screenshot, first we call API call and the save response in state and render this data with the help of FlatList and add onPress event

React-native Fetch GET request example with FlatList
React-native Fetch GET request example with FlatList

 enjoy coding… 🙂

2 Replies to “React-native Fetch GET request example with FlatList”

Leave a Reply

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