Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add a simple separator between items in a FlatList.
React Native
import React from 'react'; import { FlatList, View, Text } from 'react-native'; export default function MyList() { const data = [{key: '1'}, {key: '2'}, {key: '3'}]; return ( <FlatList data={data} renderItem={({item}) => <Text>{item.key}</Text>} ItemSeparatorComponent=[1] /> ); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a Text component instead of a View for the separator.
Not setting a height or width for the separator View.
✗ Incorrect
The ItemSeparatorComponent expects a component that renders a separator. A thin gray line with height 1 is a common separator style.
2fill in blank
mediumComplete the code to add a vertical separator between items in a horizontal FlatList.
React Native
import React from 'react'; import { FlatList, View, Text } from 'react-native'; export default function HorizontalList() { const data = [{id: 'a'}, {id: 'b'}, {id: 'c'}]; return ( <FlatList horizontal data={data} renderItem={({item}) => <Text>{item.id}</Text>} ItemSeparatorComponent=[1] /> ); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using height instead of width for the separator in a horizontal list.
Using a Text component instead of a View.
✗ Incorrect
For horizontal lists, separators are vertical lines, so width is set and height is not needed.
3fill in blank
hardFix the error in the separator component to avoid extra space between items.
React Native
const Separator = () => <View style={{height: 1, backgroundColor: 'gray', marginVertical: 10}} />;
<FlatList
data={[1,2,3]}
renderItem={({item}) => <Text>{item}</Text>}
ItemSeparatorComponent=[1]
/> Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Keeping marginVertical on the separator causes unwanted spacing.
Not using a function component for ItemSeparatorComponent.
✗ Incorrect
Adding vertical margin causes extra space between items. Removing margin fixes this.
4fill in blank
hardFill both blanks to create a custom separator with margin and color.
React Native
const CustomSeparator = () => (
<View style={{height: 1, marginVertical: [1], backgroundColor: [2] />
);
<FlatList
data={[10, 20, 30]}
renderItem={({item}) => <Text>{item}</Text>}
ItemSeparatorComponent={CustomSeparator}
/> Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using too large margin makes separator too big.
Using bright colors that distract from content.
✗ Incorrect
Margin of 8 and light gray background create a subtle separator with space.
5fill in blank
hardFill all three blanks to create a separator that is a thin red line with margin.
React Native
const RedSeparator = () => (
<View style={{height: [1], backgroundColor: [2], marginHorizontal: [3] />
);
<FlatList
data={[100, 200, 300]}
renderItem={({item}) => <Text>{item}</Text>}
ItemSeparatorComponent={RedSeparator}
/> Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using too thin height to see the red line.
Not adding margin causes separator to touch edges.
✗ Incorrect
A height of 5, red color, and horizontal margin of 10 create a visible red separator with spacing.