헤더가 있는 SectionList
SectionList로 항목을 섹션별로 묶고 각 그룹에 고정되는 섹션 헤더를 렌더링하며 항목 사이의 구분선을 사용자 지정합니다.
헤더가 있는 SectionList은(는) CoddyKit의 무료 React Native Academy 강의입니다. 이것은 4개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 React Native Academy 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. React Native Academy 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
When to Use SectionList
SectionList is the React Native component for displaying grouped lists — data divided into sections, each with its own header. It is ideal for contacts lists sorted alphabetically, settings screens with grouped options, or e-commerce categories. Like FlatList, it virtualizes rendering for performance.
SectionList Data Format
SectionList expects its sections prop to be an array of section objects. Each section object must have a data array containing the items for that section. You also typically include a title or other metadata to render the section header.
const SECTIONS = [
{
title: 'A',
data: [
{ id: '1', name: 'Alice' },
{ id: '2', name: 'Andrew' },
],
},
{
title: 'B',
data: [
{ id: '3', name: 'Bob' },
{ id: '4', name: 'Beth' },
],
},
];Rendering Items with renderItem
The renderItem function in SectionList receives an object with the current item, its index within the section, and the section object itself. This gives you access to both the item data and the enclosing section's metadata in the same render call.
const renderItem = ({ item, section }) => (
<View style={styles.row}>
<Text>{item.name}</Text>
<Text style={styles.sectionLabel}>{section.title}</Text>
</View>
);Rendering Section Headers
Pass a renderSectionHeader function to display a header above each section. The function receives { section } — the current section object. Returning a View with a colored background makes the header stand out from the items below it.
const renderSectionHeader = ({ section }) => (
<View style={styles.sectionHeader}>
<Text style={styles.sectionTitle}>{section.title}</Text>
</View>
);
<SectionList
sections={SECTIONS}
renderItem={renderItem}
renderSectionHeader={renderSectionHeader}
keyExtractor={(item) => item.id}
/>Sticky Section Headers
By default, section headers scroll with the list. Set stickySectionHeadersEnabled to true to make headers stick to the top of the screen as you scroll past them — the same behavior you see in the iOS Contacts app. This is set to true by default on iOS and false on Android.
<SectionList
sections={SECTIONS}
renderItem={renderItem}
renderSectionHeader={renderSectionHeader}
keyExtractor={(item) => item.id}
stickySectionHeadersEnabled={true}
/>Section Footer with renderSectionFooter
Use renderSectionFooter to render content after the last item in each section. This is useful for showing a 'View all' link or a count of remaining items below a truncated group. The function receives the same { section } argument as renderSectionHeader.
const renderSectionFooter = ({ section }) => (
<TouchableOpacity>
<Text style={styles.viewAll}>
View all {section.data.length} {section.title} contacts
</Text>
</TouchableOpacity>
);Item Separators in SectionList
Like FlatList, SectionList supports ItemSeparatorComponent to render dividers between items within a section. SectionList also provides SectionSeparatorComponent to render a separator between the end of one section (or its footer) and the start of the next section's header.
const ItemSeparator = () => <View style={styles.separator} />;
const SectionSeparator = () => <View style={styles.sectionSeparator} />;
<SectionList
sections={SECTIONS}
renderItem={renderItem}
renderSectionHeader={renderSectionHeader}
keyExtractor={(item) => item.id}
ItemSeparatorComponent={ItemSeparator}
SectionSeparatorComponent={SectionSeparator}
/>A Full SectionList Example
Bringing it all together: define your sections data, provide renderItem and renderSectionHeader, set a keyExtractor, and optionally enable sticky headers. This pattern covers the majority of grouped list use cases in production apps.
import { SectionList, View, Text, StyleSheet } from 'react-native';
export default function ContactsScreen() {
return (
<SectionList
sections={SECTIONS}
keyExtractor={(item) => item.id}
renderItem={({ item }) => (
<View style={styles.row}><Text>{item.name}</Text></View>
)}
renderSectionHeader={({ section }) => (
<View style={styles.header}><Text style={styles.headerText}>{section.title}</Text></View>
)}
stickySectionHeadersEnabled
/>
);
}Building Data for SectionList from a Flat Array
Often your API returns a flat array. You need to group items by a common property before passing them to SectionList. Use Array.reduce to build a map, then convert it to the sections format. Sort the sections alphabetically for a predictable order.
function groupByFirstLetter(contacts) {
const map = contacts.reduce((acc, contact) => {
const letter = contact.name[0].toUpperCase();
if (!acc[letter]) acc[letter] = [];
acc[letter].push(contact);
return acc;
}, {});
return Object.keys(map).sort().map((key) => ({
title: key,
data: map[key],
}));
}Scrolling to a Specific Section
Use a ref on the SectionList and call scrollToLocation to jump to a specific item or section header. This is essential for alphabetic index bars (like the sidebar in iOS Contacts) where tapping a letter scrolls the list to that section.
const sectionListRef = useRef(null);
const scrollToSection = (sectionIndex) => {
sectionListRef.current?.scrollToLocation({
sectionIndex,
itemIndex: 0,
animated: true,
});
};
<SectionList ref={sectionListRef} sections={SECTIONS} ... />Performance Tips for SectionList
The same performance rules that apply to FlatList apply to SectionList. Stabilize renderItem and renderSectionHeader with useCallback. Avoid creating new objects inline in the sections prop on every render — memoize the processed sections data with useMemo.
const sections = useMemo(
() => groupByFirstLetter(contacts),
[contacts]
);
const renderItem = useCallback(({ item }) => (
<Row item={item} />
), []);Quick Check
Test your understanding of SectionList with headers from this lesson.
Lesson Recap
In this lesson you learned: SectionList sections prop takes an array of objects each with a data array, renderSectionHeader renders a title above each group, and stickySectionHeadersEnabled pins headers to the top as users scroll. Next up we build a complete Contacts List App combining SectionList, search, and pull-to-refresh.
자주 묻는 질문
“헤더가 있는 SectionList” 강의는 무료인가요?
네 — “헤더가 있는 SectionList” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 React Native Academy 강의 전체를 잠금 해제할 수 있습니다. React Native Academy 강의에는 총 4개의 강의가 포함되어 있습니다.
“헤더가 있는 SectionList”에서 뭘 배우나요?
SectionList로 항목을 섹션별로 묶고 각 그룹에 고정되는 섹션 헤더를 렌더링하며 항목 사이의 구분선을 사용자 지정합니다. 브라우저에서 직접 실행하는 실습 코드로 React Native Academy을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
React Native Academy을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 React Native Academy은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 3번째 강의입니다.
“헤더가 있는 SectionList” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 React Native Academy 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 React Native Academy 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- FlatList 데이터, renderItem 및 keyExtractor
- 당겨서 새로 고침과 더 불러오기
- 헤더가 있는 SectionList
- 연락처 목록 앱 만들기