Lesson 5 of 10
SectionList & Complex Lists
SectionList is the production choice for grouped data - contacts (A-Z), settings sections, order history by date. It virtualizes exactly like FlatList but supports section headers natively.
SectionList with Sticky Headers
import { SectionList, View, Text, StyleSheet } from 'react-native';
interface Contact { id: string; name: string; phone: string; }
interface Section { title: string; data: Contact[]; }
const CONTACTS: Section[] = [
{ title: 'A', data: [{ id: '1', name: 'Alice Chen', phone: '+1 555-0101' }, { id: '2', name: 'Adam Martin', phone: '+1 555-0102' }] },
{ title: 'B', data: [{ id: '3', name: 'Bob Smith', phone: '+1 555-0201' }] },
{ title: 'S', data: [{ id: '4', name: 'Sarah Kim', phone: '+1 555-0401' }, { id: '5', name: 'Sam Johnson', phone: '+1 555-0402' }] },
];
const ContactRow = React.memo(({ item }: { item: Contact }) => (
<View style={styles.row}>
<View style={styles.avatar}><Text style={styles.avatarText}>{item.name[0]}</Text></View>
<View><Text style={styles.name}>{item.name}</Text><Text style={styles.phone}>{item.phone}</Text></View>
</View>
));
function ContactList() {
return (
<SectionList
sections={CONTACTS}
keyExtractor={item => item.id}
renderItem={({ item }) => <ContactRow item={item} />}
renderSectionHeader={({ section: { title } }) => (
<View style={styles.sectionHeader}>
<Text style={styles.sectionTitle}>{title}</Text>
</View>
)}
stickySectionHeadersEnabled={true} // headers stick to top as you scroll past them
ItemSeparatorComponent={() => <View style={{ height: 1, backgroundColor: '#1e293b', marginLeft: 72 }} />}
/>
);
}Tip
Tip
Practice SectionList Complex Lists in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.
Rendering categorized data with sticky section headers and optimized sublists
Practice Task
Note
Practice Task - (1) Write a working example of SectionList Complex Lists from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.
Quick Quiz
Common Mistake
Warning
A common mistake with SectionList Complex Lists is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready react native code.
Finished this lesson?