Challenge - 5 Problems
SectionList Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2: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>} /> ); }
Attempts:
2 left
💡 Hint
SectionList groups items by sections and shows headers for each group.
✗ Incorrect
SectionList renders each section header and its items. Here, 'Fruits' and 'Vegetables' are headers, each followed by their respective items.
📝 Syntax
intermediate2: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>} /> ); }
Attempts:
2 left
💡 Hint
Check for missing closing brackets or parentheses.
✗ Incorrect
Option A is missing the closing parenthesis for the arrow function parameter destructuring, causing a syntax error.
❓ lifecycle
advanced2: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?
Attempts:
2 left
💡 Hint
SectionList uses shallow comparison on sections prop to decide re-render.
✗ Incorrect
SectionList re-renders when the sections prop changes reference, even if content is same. Changing functions alone does not trigger re-render.
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)?
Attempts:
2 left
💡 Hint
Use scrollToLocation with sectionIndex and itemIndex to scroll to a section header.
✗ Incorrect
scrollToLocation with sectionIndex and itemIndex scrolls to the start of a section. scrollToIndex and scrollToOffset do not support sections.
🔧 Debug
expert3: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>}
/>Attempts:
2 left
💡 Hint
Check the data arrays inside each section.
✗ Incorrect
The sections have empty data arrays, so no items render; only headers are shown.