0
0
React Nativemobile~20 mins

Item separators in React Native - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Separator Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What is the output of this FlatList with a custom separator?
Consider this React Native FlatList code snippet. What will you see rendered on the screen between each item?
React Native
import React from 'react';
import { FlatList, Text, View } from 'react-native';

const data = [{key: 'A'}, {key: 'B'}, {key: 'C'}];

export default function App() {
  return (
    <FlatList
      data={data}
      renderItem={({item}) => <Text>{item.key}</Text>}
      ItemSeparatorComponent={() => <View style={{height: 2, backgroundColor: 'red'}} />}
    />
  );
}
ABlue vertical lines appear between each item.
BNo separator lines appear between items.
CRed horizontal lines of 2 pixels height appear between each item A, B, and C.
DA thick black border surrounds each item.
Attempts:
2 left
💡 Hint
Look at the style of the View returned by ItemSeparatorComponent.
ui_behavior
intermediate
2:00remaining
How many separators will appear for this FlatList?
Given a FlatList with 4 items and a custom ItemSeparatorComponent, how many separator lines will be rendered?
React Native
import React from 'react';
import { FlatList, Text, View } from 'react-native';

const data = [{key: '1'}, {key: '2'}, {key: '3'}, {key: '4'}];

export default function App() {
  return (
    <FlatList
      data={data}
      renderItem={({item}) => <Text>{item.key}</Text>}
      ItemSeparatorComponent={() => <View style={{height: 1, backgroundColor: 'gray'}} />}
    />
  );
}
A3 separators will appear, one between each pair of items.
B5 separators will appear, including before the first and after the last item.
CNo separators will appear because the component is missing a key.
D4 separators will appear, one after each item.
Attempts:
2 left
💡 Hint
Separators appear only between items, not before the first or after the last.
lifecycle
advanced
2:00remaining
Why might your custom separator not appear in FlatList?
You added an ItemSeparatorComponent to your FlatList but no separator shows. Which reason below explains this behavior?
React Native
import React from 'react';
import { FlatList, Text, View } from 'react-native';

const data = [{key: 'x'}, {key: 'y'}];

export default function App() {
  return (
    <FlatList
      data={data}
      renderItem={({item}) => <Text>{item.key}</Text>}
      ItemSeparatorComponent={null}
    />
  );
}
ASeparators appear only if renderItem returns a View, not Text.
BFlatList requires a separator key prop to render separators.
CSeparators only appear if data has more than 3 items.
DItemSeparatorComponent is set to null, so no separator is rendered.
Attempts:
2 left
💡 Hint
Check the value assigned to ItemSeparatorComponent.
📝 Syntax
advanced
2:00remaining
Which option correctly defines a separator with padding in FlatList?
You want a separator with 10 pixels vertical padding and a 1 pixel black line. Which code snippet is correct?
AItemSeparatorComponent={() => <View style={{paddingVertical: 10, borderBottomWidth: 1, borderBottomColor: 'black'}} />}
BItemSeparatorComponent={() => <View style={{padding: 10, borderBottom: '1px solid black'}} />}
CItemSeparatorComponent={() => <View style={{marginVertical: 10, borderWidth: 1, borderColor: 'black'}} />}
DItemSeparatorComponent={() => <View style={{paddingVertical: 10, borderBottomWidth: 1, borderColor: 'black'}} />}
Attempts:
2 left
💡 Hint
React Native styles use borderBottomWidth and borderBottomColor, not CSS strings.
🧠 Conceptual
expert
2:00remaining
What is the main difference between ItemSeparatorComponent and ListFooterComponent in FlatList?
Choose the statement that best describes the difference between ItemSeparatorComponent and ListFooterComponent in React Native FlatList.
ABoth render between items but ListFooterComponent has a fixed height.
BItemSeparatorComponent renders between items; ListFooterComponent renders once at the end of the list.
CItemSeparatorComponent renders only at the start; ListFooterComponent renders between items.
DItemSeparatorComponent is for headers; ListFooterComponent is for footers.
Attempts:
2 left
💡 Hint
Think about where each component appears in the list layout.