Bird
Raised Fist0
React Nativemobile~20 mins

Item separators in React Native - Practice Problems & Coding Challenges

Choose your learning style10 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.

Practice

(1/5)
1. What is the main purpose of using ItemSeparatorComponent in a FlatList in React Native?
easy
A. To visually separate list items for better readability
B. To add animations between list items
C. To sort the list items alphabetically
D. To load more items when scrolling

Solution

  1. Step 1: Understand the role of ItemSeparatorComponent

    This prop is used to add a visual separator between items in a list.
  2. Step 2: Identify the effect on UI

    It improves readability by visually dividing items, not for sorting or animations.
  3. Final Answer:

    To visually separate list items for better readability -> Option A
  4. Quick Check:

    ItemSeparatorComponent = Visual separation [OK]
Hint: Separators divide items visually, not functionally [OK]
Common Mistakes:
  • Confusing separators with sorting or animations
  • Thinking separators load more data
  • Assuming separators change item order
2. Which of the following is the correct way to add a simple horizontal separator between items in a FlatList?
easy
A. ItemSeparator={() => <View style={{height: 10, backgroundColor: 'red'}} />}
B. separator={() => <View style={{width: 1, backgroundColor: 'gray'}} />}
C. ItemSeparatorComponent={() => <View style={{height: 1, backgroundColor: 'gray'}} />}
D. SeparatorComponent={() => <View style={{height: 1, backgroundColor: 'blue'}} />}

Solution

  1. Step 1: Identify the correct prop name

    The correct prop is ItemSeparatorComponent in FlatList.
  2. Step 2: Check the separator style

    A horizontal separator uses a small height and a background color, typically height: 1.
  3. Final Answer:

    ItemSeparatorComponent={() => <View style={{height: 1, backgroundColor: 'gray'}} />} -> Option C
  4. Quick Check:

    Correct prop and style = ItemSeparatorComponent={() => <View style={{height: 1, backgroundColor: 'gray'}} />} [OK]
Hint: Use ItemSeparatorComponent with height for horizontal lines [OK]
Common Mistakes:
  • Using wrong prop names like separator or SeparatorComponent
  • Setting width instead of height for horizontal separators
  • Using too large height or wrong colors
3. Given this code snippet, what will be the visual result of the FlatList?
const data = ['Apple', 'Banana', 'Cherry'];

<FlatList
  data={data}
  renderItem={({item}) => <Text>{item}</Text>}
  ItemSeparatorComponent={() => <View style={{height: 2, backgroundColor: 'black'}} />}
/>
medium
A. A list of fruits with no separators visible
B. A list of fruits with separators only after the last item
C. A list of fruits with thick red lines between items
D. A list of fruits with a thin black line between each item

Solution

  1. Step 1: Analyze the separator component

    The separator is a View with height 2 and black background, so a thin black line.
  2. Step 2: Understand separator placement

    Separators appear between each item, not after the last one.
  3. Final Answer:

    A list of fruits with a thin black line between each item -> Option D
  4. Quick Check:

    ItemSeparatorComponent creates black lines between items [OK]
Hint: Separator style defines line thickness and color [OK]
Common Mistakes:
  • Thinking separators appear after last item
  • Confusing separator color or thickness
  • Assuming no separators show without extra code
4. What is wrong with this FlatList code that tries to add separators?
<FlatList
  data={[1,2,3]}
  renderItem={({item}) => <Text>Item {item}</Text>}
  ItemSeparatorComponent="<View style={{height: 1, backgroundColor: 'gray'}} />"
/>
medium
A. The separator is passed as a string instead of a function component
B. The data array is invalid
C. The renderItem function is missing parentheses
D. The separator style uses height instead of width

Solution

  1. Step 1: Check how ItemSeparatorComponent is passed

    It is passed as a string, which is incorrect. It must be a function returning a component.
  2. Step 2: Verify other parts

    Data and renderItem are correct; height is correct for horizontal separator.
  3. Final Answer:

    The separator is passed as a string instead of a function component -> Option A
  4. Quick Check:

    ItemSeparatorComponent must be a function, not a string [OK]
Hint: Pass separator as function, not string [OK]
Common Mistakes:
  • Passing JSX as string instead of function
  • Confusing height and width for separator style
  • Incorrect renderItem syntax
5. You want to create a FlatList with vertical items and a custom separator that is a 10-pixel tall red line with 20 pixels horizontal margin on each side. Which code snippet correctly implements this separator?
hard
A. ItemSeparatorComponent={() => <View style={{height: 10, backgroundColor: 'red', marginVertical: 20}} />}
B. ItemSeparatorComponent={() => <View style={{height: 10, backgroundColor: 'red', marginHorizontal: 20}} />}
C. ItemSeparatorComponent={() => <View style={{width: 10, backgroundColor: 'red', marginVertical: 20}} />}
D. ItemSeparatorComponent={() => <View style={{width: 10, backgroundColor: 'red', marginHorizontal: 20}} />}

Solution

  1. Step 1: Understand vertical list separator style

    For vertical lists, separator height controls thickness; width is full width by default.
  2. Step 2: Apply margin for horizontal spacing

    Use marginHorizontal: 20 to add space on left and right sides.
  3. Step 3: Check color and size

    Height 10 and backgroundColor red matches the requirement.
  4. Final Answer:

    ItemSeparatorComponent={() => <View style={{height: 10, backgroundColor: 'red', marginHorizontal: 20}} />} -> Option B
  5. Quick Check:

    Vertical separator uses height + marginHorizontal [OK]
Hint: Vertical separator uses height and marginHorizontal for side space [OK]
Common Mistakes:
  • Using width instead of height for vertical separators
  • Using marginVertical instead of marginHorizontal for side margins
  • Confusing margin directions
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard