0
0
React Nativemobile~20 mins

ListEmptyComponent in React Native - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ListEmptyComponent Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2: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>}
    />
  );
}
AThe FlatList will crash because data is empty.
BNothing will be displayed; the screen will be blank.
CThe text 'No items found' will be displayed on the screen.
DThe FlatList will show a loading spinner automatically.
Attempts:
2 left
💡 Hint
Think about what ListEmptyComponent is used for in FlatList.
lifecycle
intermediate
1:30remaining
When does ListEmptyComponent render in FlatList?
In React Native FlatList, under which condition does the ListEmptyComponent render?
AWhen the FlatList is scrolled to the bottom.
BWhen the data prop has at least one item.
COnly when the FlatList is loading data asynchronously.
DWhen the data prop is an empty array or undefined.
Attempts:
2 left
💡 Hint
Think about when the list has no items to show.
📝 Syntax
advanced
2:00remaining
Identify the correct way to define ListEmptyComponent
Which of the following is the correct syntax to provide a ListEmptyComponent in FlatList?
AListEmptyComponent='No data'
BListEmptyComponent={() => <Text>No data</Text>}
CListEmptyComponent={<Text>No data</Text>}
DListEmptyComponent={Text('No data')}
Attempts:
2 left
💡 Hint
ListEmptyComponent expects a React component or a function returning one.
🔧 Debug
advanced
2: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>}
    />
  );
}
AListEmptyComponent is given a React element instead of a function, causing it not to render.
BThe data array is empty, so ListEmptyComponent should show; the problem is elsewhere.
CThe keyExtractor prop is missing, causing FlatList to fail silently.
DrenderItem is missing a return statement, so the list fails to render.
Attempts:
2 left
💡 Hint
Check how ListEmptyComponent is passed in the code.
🧠 Conceptual
expert
3: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?
ADefine a separate functional component with styles and a button, then pass it as ListEmptyComponent={MyEmptyComponent}.
BPass a plain string to ListEmptyComponent and handle styling inside FlatList props.
CSet ListEmptyComponent to null and show a modal with reload button outside FlatList.
DUse ListEmptyComponent={() => <Text>No data</Text>} and add styles inline without interaction.
Attempts:
2 left
💡 Hint
Think about how to include multiple elements and interaction inside ListEmptyComponent.