Component - ListEmptyComponent
The ListEmptyComponent in React Native is a special component that shows a message or UI when a list has no items to display. It helps users understand that the list is empty instead of showing a blank screen.
The ListEmptyComponent in React Native is a special component that shows a message or UI when a list has no items to display. It helps users understand that the list is empty instead of showing a blank screen.
FlatList ├── ListEmptyComponent │ └── View │ └── Text └── ListItem (not rendered when empty)
ListEmptyComponent prop in a React Native FlatList?ListEmptyComponentListEmptyComponent in a FlatList?Text component.Text as a function incorrectly. Text('No items')} /> calls Text incorrectly inside the function. passes a string, which is invalid.import React from 'react';
import { FlatList, Text } from 'react-native';
export default function MyList() {
return (
<FlatList
data={[]}
renderItem={({ item }) => <Text>{item}</Text>}
ListEmptyComponent={() => <Text>No data found</Text>}
/>
);
}FlatList usage:
<FlatList
data={[]}
renderItem={({ item }) => <Text>{item}</Text>}
ListEmptyComponent={Text('No items')}
/>Text('No items'), which calls the Text function incorrectly instead of passing a component or function.renderItem is correct for empty data (though keys are recommended but not error here). Empty data is allowed. Text can be used inside FlatList.FlatList is empty. Which is the best way to implement ListEmptyComponent to achieve this?ListEmptyComponent is invalid because ListEmptyComponent does not accept strings. Use renderItem to render the message when data is empty misuses renderItem which only renders list items. Set ListEmptyComponent to null and show message outside the list moves the message outside the list, which is less integrated.Pass the test and this pattern moves unknown