Displaying a list of data fetched from an API is one of the most common tasks in React Native apps. Typically, this is achieved using the FlatList component combined with asynchronous API calls.
useEffect for lifecycle handlinguseStateFlatListReact Native provides the FlatList component for rendering large lists efficiently. Data is usually fetched inside useEffect and stored in state.
// React Native FlatList with API data example
import React, { useEffect, useState } from "react";
import { View, Text, FlatList } from "react-native";
const App = () => {
const [users, setUsers] = useState([]);
useEffect(() => {
fetch("https://jsonplaceholder.typicode.com/users")
.then(response => response.json())
.then(data => setUsers(data));
}, []);
return (
item.id.toString()}
renderItem={({ item }) => (
{item.name}
)}
/>
);
};
export default App;
The app fetches user data from an API when the screen loads. Each user name is displayed in a scrollable list using FlatList.
Click the button below to simulate fetching data from a real API and rendering it into a list, just like React Native does.
List is empty.
keyExtractor