0
0
React Nativemobile~20 mins

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

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