티스토리 뷰
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 키를 가진 객체)를 말한다.
[형태]
[참고자료]
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
- nodeJS
- 문제풀이
- python
- dfs
- 알고리즘
- Spotify
- 백트래킹
- flutter
- rn
- 코딩테스트
- 비동기
- React-native
- 코테
- node.js
- 코드분석
- Unsplash
- 프로그래머스
- 파이썬
- React.js
- Python3
- fetch
- p5js
- DP
- 백준
- 이벤트루프
- javascript
- React
- backtracking
- 코어자바스크립트
- 다이나믹프로그래밍
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |