티스토리 뷰

ScrollView 안에 FlatList나 ScrollView를 사용해서 발생한 오류이다.

우선 기본적으로 FlatList에 scroll이 적용되니, 단순히 스크롤이 하나 필요한 거라면 같이 사용하지 않는다. 다른 요소를 FlatList와 함께 사용하고 싶다면 ListHeaderComponentListFooterComponent에 다른 요소를 집어넣는다.

// Nope ❌
<ScrollView>
  <CategoryBar />
  <FlatList
    data={DATA}
    renderItem={renderItem}
    keyExtractor={item => item.id}
  />
</ScrollView>

// Use this ✅
<FlatList
  ListHeaderComponent={<CategoryBar />}
  data={DATA}
  renderItem={renderItem}
  keyExtractor={item => item.id}
/>

 

[형태]

FlatList와 ListHeaderComponent

 

각 FlatList마다 CatgoryBar를 넣고 싶다면 SectionList를 사용한다.

const DATA = [
  {
    title: "Category1",
    data: ["Pizza", "Burger", "Risotto"]
  },
  {
    title: "Category2",
    data: ["French Fries", "Onion Rings", "Fried Shrimps"]
  },
  {
    title: "Category3",
    data: ["Water", "Coke", "Beer"]
  },
  {
    title: "Category4",
    data: ["Cheese Cake", "Ice Cream"]
  }
];

// ...

<SectionList
  sections={DATA}
  keyExtractor={(item, index) => item + index}
  renderItem={({ item }) => <Item title={item} />}
  renderSectionHeader={({ section: { title } }) => (
  	<Text style={styles.header}>{title}</Text>
  )}
/>

여기서 itemdata 배열의 한 요소이고, sectionDATA 전체 중 한 요소(title, data 키를 가진 객체)를 말한다.

[형태]

SectionList


[참고자료]

 

How to Fix ‘VirtualizedLists should never be nested inside plain ScrollViews’ Warning

How to Fix ‘VirtualizedLists should never be nested inside plain ScrollViews’ Warning

javascript.plainenglish.io

 

 

SectionList · React Native

A performant interface for rendering sectioned lists, supporting the most handy features:

reactnative.dev

 

 

FlatList · React Native

A performant interface for rendering basic, flat lists, supporting the most handy features:

reactnative.dev

 

'🐛 버그' 카테고리의 다른 글

Date 객체를 JSON.stringfy(), JSON.parse() 할 때  (0) 2021.12.27
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
글 보관함