티스토리 뷰
🐛 버그
VirtualizedLists should never be nested inside plain ScrollViews with the same orientation - use another VirtualizedList - backed contained instead. | React Native
yeonDev 2021. 12. 27. 10:43ScrollView 안에 FlatList나 ScrollView를 사용해서 발생한 오류이다.
우선 기본적으로 FlatList에 scroll이 적용되니, 단순히 스크롤이 하나 필요한 거라면 같이 사용하지 않는다. 다른 요소를 FlatList와 함께 사용하고 싶다면 ListHeaderComponent와 ListFooterComponent에 다른 요소를 집어넣는다.
// 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마다 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>
)}
/>
여기서 item은 data 배열의 한 요소이고, section은 DATA 전체 중 한 요소(title, data 키를 가진 객체)를 말한다.
[형태]
[참고자료]
'🐛 버그' 카테고리의 다른 글
Date 객체를 JSON.stringfy(), JSON.parse() 할 때 (0) | 2021.12.27 |
---|
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- DP
- 비동기
- React
- 동기
- p5js
- 다이나믹프로그래밍
- Unsplash
- fetch
- 프로그래머스
- 프로젝트
- React-native
- python
- 키워드밑줄
- Python3
- 코어자바스크립트
- 판례암기
- 코딩테스트
- 코드분석
- flutter
- node.js
- Spotify
- React.js
- 감시피하기
- rn
- 파이썬
- backtracking
- 백준
- 웅진IT
- 코테
- dfs
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함