0Pricing
React Native Academy · 강의

FlatList 데이터, renderItem 및 keyExtractor

배열을 FlatList의 data prop으로 전달하고, 스타일이 지정된 행 컴포넌트를 반환하도록 renderItem을 구현하며, 안정적인 목록 식별을 위해 keyExtractor를 제공합니다.

FlatList 데이터, renderItem 및 keyExtractor은(는) CoddyKit의 무료 React Native Academy 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 React Native Academy 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. React Native Academy 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Why FlatList Instead of ScrollView?

ScrollView renders all its children at once, which becomes slow when displaying hundreds of items. FlatList virtualizes the list — it only renders the items currently visible on screen plus a small buffer, dramatically reducing memory usage and improving scroll performance for large datasets.

The data Prop

Pass your array of items to the data prop. FlatList iterates over this array and calls renderItem for each element. The array can contain any kind of JavaScript objects. Changes to the data array trigger a re-render of affected list items.

const DATA = [
  { id: '1', name: 'Alice' },
  { id: '2', name: 'Bob' },
  { id: '3', name: 'Carol' },
];

<FlatList data={DATA} ... />

The renderItem Prop

The renderItem prop is a function that receives an object with an item property (the current array element) and must return a React element. This is where you define how each row looks. Keep it as a stable reference using useCallback to avoid unnecessary re-renders.

const renderItem = ({ item }) => (
  <View style={styles.row}>
    <Text>{item.name}</Text>
  </View>
);

<FlatList
  data={DATA}
  renderItem={renderItem}
/>

The keyExtractor Prop

keyExtractor tells FlatList how to extract a unique string key from each item. React uses these keys to track which items changed during re-renders. Without a proper key extractor FlatList falls back to the array index, which can cause subtle bugs during data mutations.

<FlatList
  data={DATA}
  renderItem={renderItem}
  keyExtractor={(item) => item.id}
/>

A Complete FlatList Example

Combining data, renderItem, and keyExtractor gives you a fully functional, scrollable, virtualized list. You can style the rows inside renderItem just like any other component. FlatList automatically handles scroll and touch events.

import { FlatList, View, Text, StyleSheet } from 'react-native';

const DATA = [
  { id: '1', title: 'First Item' },
  { id: '2', title: 'Second Item' },
  { id: '3', title: 'Third Item' },
];

export default function App() {
  return (
    <FlatList
      data={DATA}
      keyExtractor={(item) => item.id}
      renderItem={({ item }) => (
        <View style={styles.item}>
          <Text>{item.title}</Text>
        </View>
      )}
    />
  );
}

const styles = StyleSheet.create({
  item: { padding: 16, borderBottomWidth: 1, borderColor: '#eee' },
});

Adding a List Header and Footer

Use ListHeaderComponent to render content above the list (such as a search bar or page title) and ListFooterComponent for content below (such as a loading spinner when fetching more data). These components scroll with the list, unlike a view placed outside FlatList.

<FlatList
  data={DATA}
  renderItem={renderItem}
  keyExtractor={(item) => item.id}
  ListHeaderComponent={() => <Text style={styles.header}>Users</Text>}
  ListFooterComponent={() => <ActivityIndicator />}
/>

Empty List with ListEmptyComponent

When the data array is empty, FlatList renders nothing by default. Provide a ListEmptyComponent to display a placeholder message or illustration when there are no items. This is much cleaner than wrapping FlatList in a conditional.

<FlatList
  data={filteredData}
  renderItem={renderItem}
  keyExtractor={(item) => item.id}
  ListEmptyComponent={() => (
    <Text style={styles.empty}>No results found</Text>
  )}
/>

Item Separators with ItemSeparatorComponent

Instead of adding border styles directly to item rows, use ItemSeparatorComponent to render a separator between items. React Native only renders the separator between items, not before the first or after the last, which avoids double borders at the edges.

const Separator = () => (
  <View style={{ height: 1, backgroundColor: '#eee' }} />
);

<FlatList
  data={DATA}
  renderItem={renderItem}
  keyExtractor={(item) => item.id}
  ItemSeparatorComponent={Separator}
/>

Horizontal FlatList

Set the horizontal prop to true to render a horizontally scrolling list. This is useful for carousels, category chips, or story rows. The showsHorizontalScrollIndicator prop can hide the scroll bar for a cleaner look.

<FlatList
  horizontal
  showsHorizontalScrollIndicator={false}
  data={categories}
  renderItem={({ item }) => (
    <View style={styles.chip}>
      <Text>{item.label}</Text>
    </View>
  )}
  keyExtractor={(item) => item.id}
/>

Scrolling to an Index Programmatically

Use the ref on FlatList and call flatListRef.current.scrollToIndex({ index, animated: true }) to jump to a specific item. You can also use scrollToOffset for pixel-level control or scrollToEnd to scroll to the bottom of the list.

const flatListRef = useRef(null);

const scrollToTop = () => {
  flatListRef.current.scrollToIndex({ index: 0, animated: true });
};

<FlatList ref={flatListRef} data={DATA} renderItem={renderItem} />

Avoiding Common FlatList Mistakes

Avoid defining renderItem as an anonymous arrow function directly in JSX (renderItem={() => ...}). This creates a new function reference on every render, causing every row to re-render unnecessarily. Define it outside the JSX or memoize it with useCallback. Also never use an array index as the key — always use a stable unique ID.

// Bad: anonymous function in JSX
<FlatList renderItem={({ item }) => <Row item={item} />} />

// Good: stable reference
const renderItem = useCallback(({ item }) => <Row item={item} />, []);
<FlatList renderItem={renderItem} />

Quick Check

Test your understanding of FlatList data, renderItem, and keyExtractor from this lesson.

Lesson Recap

In this lesson you learned: FlatList virtualizes large lists by only rendering visible items, renderItem defines the appearance of each row, and keyExtractor provides stable unique keys for efficient React reconciliation. Next up we explore pull-to-refresh and infinite scroll with load more.

자주 묻는 질문

“FlatList 데이터, renderItem 및 keyExtractor” 강의는 무료인가요?

네 — “FlatList 데이터, renderItem 및 keyExtractor” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 React Native Academy 강의 전체를 잠금 해제할 수 있습니다. React Native Academy 강의에는 총 4개의 강의가 포함되어 있습니다.

“FlatList 데이터, renderItem 및 keyExtractor”에서 뭘 배우나요?

배열을 FlatList의 data prop으로 전달하고, 스타일이 지정된 행 컴포넌트를 반환하도록 renderItem을 구현하며, 안정적인 목록 식별을 위해 keyExtractor를 제공합니다. 브라우저에서 직접 실행하는 실습 코드로 React Native Academy을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

React Native Academy을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 React Native Academy은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.

“FlatList 데이터, renderItem 및 keyExtractor” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 React Native Academy 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 React Native Academy 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. FlatList 데이터, renderItem 및 keyExtractor
  2. 당겨서 새로 고침과 더 불러오기
  3. 헤더가 있는 SectionList
  4. 연락처 목록 앱 만들기
← React Native Academy(으)로 돌아가기