Bird
Raised Fist0
React Nativemobile~20 mins

SectionList for grouped data in React Native - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
SectionList Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate
2:00remaining
What will this SectionList render?
Consider this React Native code snippet using SectionList. What will the UI show?
React Native
import React from 'react';
import { SectionList, Text, View } from 'react-native';

const DATA = [
  { title: 'Fruits', data: ['Apple', 'Banana'] },
  { title: 'Vegetables', data: ['Carrot', 'Peas'] }
];

export default function App() {
  return (
    <SectionList
      sections={DATA}
      keyExtractor={(item, index) => item + index}
      renderItem={({ item }) => <Text>{item}</Text>}
      renderSectionHeader={({ section }) => <Text>{section.title}</Text>}
    />
  );
}
AA flat list showing all items without any headers.
BAn empty screen because data is not correctly passed.
COnly the section headers 'Fruits' and 'Vegetables' are shown, no items.
DA list with two headers: 'Fruits' and 'Vegetables', each followed by their items.
Attempts:
2 left
💡 Hint
SectionList groups items by sections and shows headers for each group.
📝 Syntax
intermediate
2:00remaining
Identify the syntax error in this SectionList usage
Which option contains a syntax error that will prevent this SectionList from rendering?
React Native
import React from 'react';
import { SectionList, Text } from 'react-native';

const DATA = [
  { title: 'A', data: ['Item1'] }
];

export default function App() {
  return (
    <SectionList
      sections={DATA}
      keyExtractor={(item) => item}
      renderItem={({ item }) => <Text>{item}</Text>}
      renderSectionHeader={({ section }) => <Text>{section.title}</Text>}
    />
  );
}
ArenderSectionHeader={({ section => <Text>{section.title}</Text>}
BkeyExtractor={(item) => item}
CrenderItem={({ item }) => <Text>{item}</Text>}
Dsections={DATA}
Attempts:
2 left
💡 Hint
Check for missing closing brackets or parentheses.
❓ lifecycle
advanced
2:00remaining
When does SectionList re-render its items?
Given a SectionList with static sections prop, which action will cause it to re-render its items?
AUpdating the sections prop with a new array reference but same content.
BChanging the keyExtractor function to a new function instance.
CUpdating the renderItem function to a new function instance.
DChanging the state unrelated to SectionList.
Attempts:
2 left
💡 Hint
SectionList uses shallow comparison on sections prop to decide re-render.
❓ navigation
advanced
2:00remaining
How to scroll to a specific section in SectionList?
Which method and parameters correctly scroll SectionList to the 'Vegetables' section (index 1)?
AsectionListRef.current.scrollToIndex({ index: 1 })
BsectionListRef.current.scrollToLocation({ sectionIndex: 1, itemIndex: 0 })
CsectionListRef.current.scrollToOffset({ offset: 1 })
DsectionListRef.current.scrollToSection({ section: 'Vegetables' })
Attempts:
2 left
💡 Hint
Use scrollToLocation with sectionIndex and itemIndex to scroll to a section header.
🔧 Debug
expert
3:00remaining
Why does SectionList not display any items?
Given this code, why does the SectionList render only headers but no items?
React Native
const DATA = [
  { title: 'Group1', data: [] },
  { title: 'Group2', data: [] }
];

<SectionList
  sections={DATA}
  keyExtractor={(item, index) => item + index}
  renderItem={({ item }) => <Text>{item}</Text>}
  renderSectionHeader={({ section }) => <Text>{section.title}</Text>}
/>
ABecause renderItem is missing a return statement.
BBecause keyExtractor returns duplicate keys causing rendering issues.
CBecause the first section's data array is empty, so no items show for it.
DBecause sections prop is not an array.
Attempts:
2 left
💡 Hint
Check the data arrays inside each section.

Practice

(1/5)
1. What is the main purpose of using SectionList in React Native?
easy
A. To display a list of items grouped by sections with headers
B. To create a grid layout of images
C. To handle user input forms
D. To navigate between screens

Solution

  1. Step 1: Understand SectionList usage

    SectionList is designed to show lists grouped by sections, each with a header and items.
  2. Step 2: Compare options with SectionList purpose

    Options B, C, and D describe other UI or functionality unrelated to grouped lists.
  3. Final Answer:

    To display a list of items grouped by sections with headers -> Option A
  4. Quick Check:

    SectionList = grouped list display [OK]
Hint: SectionList groups items with headers, unlike FlatList [OK]
Common Mistakes:
  • Confusing SectionList with FlatList
  • Thinking SectionList is for navigation
  • Assuming SectionList creates grids
2. Which of the following is the correct way to define the sections prop for a SectionList?
easy
A. [{ title: 'Fruits', data: ['Apple', 'Banana'] }, { title: 'Veggies', data: ['Carrot'] }]
B. ['Fruits', 'Apple', 'Banana', 'Veggies', 'Carrot']
C. { title: 'Fruits', items: ['Apple', 'Banana'] }
D. [{ header: 'Fruits', items: ['Apple', 'Banana'] }]

Solution

  1. Step 1: Recall SectionList sections structure

    Each section is an object with a title and a data array of items.
  2. Step 2: Check options for correct keys and structure

    [{ title: 'Fruits', data: ['Apple', 'Banana'] }, { title: 'Veggies', data: ['Carrot'] }] matches the required format. Options B, C, and D use wrong keys or structure.
  3. Final Answer:

    [{ title: 'Fruits', data: ['Apple', 'Banana'] }, { title: 'Veggies', data: ['Carrot'] }] -> Option A
  4. Quick Check:

    sections = array of {title, data} objects [OK]
Hint: Sections need title and data keys exactly [OK]
Common Mistakes:
  • Using wrong keys like 'items' or 'header'
  • Passing a flat array instead of array of objects
  • Confusing data array with section title
3. Given this code snippet, what will be displayed as section headers?
const sections = [
  { title: 'A', data: ['Apple', 'Apricot'] },
  { title: 'B', data: ['Banana'] }
];

<SectionList
  sections={sections}
  renderItem={({ item }) => <Text>{item}</Text>}
  renderSectionHeader={({ section }) => <Text>{section.title}</Text>}
/>
medium
A. No headers will be shown
B. Apple and Banana as headers
C. Only A as header, B is ignored
D. A and B as headers above their items

Solution

  1. Step 1: Understand renderSectionHeader usage

    The renderSectionHeader renders the title of each section as header.
  2. Step 2: Identify section titles in data

    Sections have titles 'A' and 'B', so these will be shown as headers above their items.
  3. Final Answer:

    A and B as headers above their items -> Option D
  4. Quick Check:

    Section titles = headers [OK]
Hint: Section headers come from section.title, not items [OK]
Common Mistakes:
  • Thinking items become headers
  • Assuming only first section shows header
  • Forgetting to use renderSectionHeader
4. What is wrong with this SectionList usage?
const sections = [
  { title: 'Numbers', data: 12345 }
];

<SectionList
  sections={sections}
  renderItem={({ item }) => <Text>{item}</Text>}
  renderSectionHeader={({ section }) => <Text>{section.title}</Text>}
/>
medium
A. The title property must be an array
B. The data property should be an array, not a number
C. renderItem should be renderSectionFooter
D. sections should be a flat array, not array of objects

Solution

  1. Step 1: Check the type of data property

    The data property must be an array of items, but here it is a number (12345).
  2. Step 2: Understand consequences of wrong data type

    This will cause runtime errors because SectionList expects an array to iterate over.
  3. Final Answer:

    The data property should be an array, not a number -> Option B
  4. Quick Check:

    data must be array [OK]
Hint: data must always be an array, never a single value [OK]
Common Mistakes:
  • Passing a single value instead of array to data
  • Confusing title type with data type
  • Using wrong render method names
5. You want to display a SectionList with sections for weekdays and weekend, but only show days that start with 'S'. How should you prepare the sections data?
hard
A. [{ title: 'Weekdays', data: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] }]
B. [{ title: 'Weekdays', data: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'] }, { title: 'Weekend', data: ['Saturday', 'Sunday'] }]
C. [{ title: 'Weekdays', data: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'].filter(day => day.startsWith('S')) }, { title: 'Weekend', data: ['Saturday', 'Sunday'].filter(day => day.startsWith('S')) }]
D. [{ title: 'Days', data: ['Saturday', 'Sunday'] }]

Solution

  1. Step 1: Filter days starting with 'S' in each group

    Use filter(day => day.startsWith('S')) on weekdays and weekend arrays to keep only days starting with 'S'.
  2. Step 2: Assign filtered arrays to correct section titles

    Weekdays filtered will be empty, weekend filtered will have 'Saturday' and 'Sunday'. This matches the requirement.
  3. Final Answer:

    [{ title: 'Weekdays', data: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'].filter(day => day.startsWith('S')) }, { title: 'Weekend', data: ['Saturday', 'Sunday'].filter(day => day.startsWith('S')) }] -> Option C
  4. Quick Check:

    Filter each section's data by startsWith('S') [OK]
Hint: Filter each section's data array before passing to SectionList [OK]
Common Mistakes:
  • Not filtering weekdays, showing all days
  • Combining all days into one section
  • Ignoring filtering and passing raw arrays
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