Challenge - 5 Problems
ListEmptyComponent Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What will be displayed when FlatList data is empty?
Consider this React Native FlatList component with a ListEmptyComponent defined. What will the user see when the data array is empty?
React Native
import React from 'react'; import { FlatList, Text, View } from 'react-native'; export default function MyList() { const data = []; return ( <FlatList data={data} keyExtractor={item => item.id} renderItem={({ item }) => <Text>{item.name}</Text>} ListEmptyComponent={() => <Text>No items found</Text>} /> ); }
Attempts:
2 left
💡 Hint
Think about what ListEmptyComponent is used for in FlatList.
✗ Incorrect
ListEmptyComponent is a special prop in FlatList that renders when the data array is empty. Here, it shows the text 'No items found'.
❓ lifecycle
intermediate1:30remaining
When does ListEmptyComponent render in FlatList?
In React Native FlatList, under which condition does the ListEmptyComponent render?
Attempts:
2 left
💡 Hint
Think about when the list has no items to show.
✗ Incorrect
ListEmptyComponent renders only when the data array is empty or missing, indicating no items to display.
📝 Syntax
advanced2:00remaining
Identify the correct way to define ListEmptyComponent
Which of the following is the correct syntax to provide a ListEmptyComponent in FlatList?
Attempts:
2 left
💡 Hint
ListEmptyComponent expects a React component or a function returning one.
✗ Incorrect
ListEmptyComponent should be a React element or a function returning a React element. Option B correctly uses a function returning a Text component.
🔧 Debug
advanced2:30remaining
Why does ListEmptyComponent not show despite empty data?
A developer uses FlatList with data = [] and ListEmptyComponent defined, but the empty component does not appear. What is the most likely cause?
React Native
import React from 'react'; import { FlatList, Text } from 'react-native'; export default function MyList() { const data = []; return ( <FlatList data={data} renderItem={({ item }) => <Text>{item.name}</Text>} ListEmptyComponent={<Text>No items</Text>} /> ); }
Attempts:
2 left
💡 Hint
Check how ListEmptyComponent is passed in the code.
✗ Incorrect
ListEmptyComponent should be a component or a function returning a component, not a React element directly. Passing a React element causes it not to render properly.
🧠 Conceptual
expert3:00remaining
How to customize ListEmptyComponent with styles and interaction?
You want to show a styled message with a button inside ListEmptyComponent that reloads data when pressed. Which approach is best?
Attempts:
2 left
💡 Hint
Think about how to include multiple elements and interaction inside ListEmptyComponent.
✗ Incorrect
A separate functional component allows styling and interaction like buttons. Passing it as ListEmptyComponent lets FlatList render it when empty.