ListEmptyComponent shows a message or view when a list has no items. It helps users understand the list is empty instead of seeing a blank screen.
ListEmptyComponent in React Native
import { FlatList, Text, View } from 'react-native'; <FlatList data={dataArray} renderItem={({ item }) => <Text>{item.name}</Text>} ListEmptyComponent={() => ( <View> <Text>No items available</Text> </View> )} />
The ListEmptyComponent prop accepts a React component or a function returning a component.
This component only shows when the data array is empty.
ListEmptyComponent={() => <Text>No data found</Text>}ListEmptyComponent={<Text style={{color: 'gray'}}>Nothing here yet!</Text>}ListEmptyComponent={() => (
<View style={{alignItems: 'center'}}>
<Text>No items</Text>
<Text>Add some to get started.</Text>
</View>
)}This app shows a list with no items. Because the list is empty, the ListEmptyComponent displays a friendly message in the center.
import React from 'react'; import { FlatList, Text, View, SafeAreaView, StyleSheet } from 'react-native'; export default function App() { const emptyData = []; return ( <SafeAreaView style={styles.container}> <FlatList data={emptyData} keyExtractor={(item, index) => index.toString()} renderItem={({ item }) => <Text style={styles.item}>{item}</Text>} ListEmptyComponent={() => ( <View style={styles.emptyContainer}> <Text style={styles.emptyText}>No items to display</Text> </View> )} /> </SafeAreaView> ); } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center' }, item: { fontSize: 18, padding: 10 }, emptyContainer: { alignItems: 'center' }, emptyText: { fontSize: 20, color: 'gray' } });
The ListEmptyComponent only shows if the data array is empty or undefined.
Time complexity is not affected by this component; it just renders conditionally.
Common mistake: forgetting to provide a keyExtractor or unique keys for list items.
Use ListEmptyComponent to improve user experience by clearly showing empty states instead of blank screens.
ListEmptyComponent shows a message or view when the list has no data.
It helps users understand the list is empty and can guide them on what to do next.
You can pass a component or a function returning a component to ListEmptyComponent.