Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Build performant React Native and Expo apps with best practices for lists, animations, and navigation
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
rules/list-performance-virtualize.md
1---2title: Use a List Virtualizer for Any List3impact: HIGH4impactDescription: reduced memory, faster mounts5tags: lists, performance, virtualization, scrollview6---78## Use a List Virtualizer for Any List910Use a list virtualizer like LegendList or FlashList instead of ScrollView with11mapped children—even for short lists. Virtualizers only render visible items,12reducing memory usage and mount time. ScrollView renders all children upfront,13which gets expensive quickly.1415**Incorrect (ScrollView renders all items at once):**1617```tsx18function Feed({ items }: { items: Item[] }) {19return (20<ScrollView>21{items.map((item) => (22<ItemCard key={item.id} item={item} />23))}24</ScrollView>25)26}27// 50 items = 50 components mounted, even if only 10 visible28```2930**Correct (virtualizer renders only visible items):**3132```tsx33import { LegendList } from '@legendapp/list'3435function Feed({ items }: { items: Item[] }) {36return (37<LegendList38data={items}39// if you aren't using React Compiler, wrap these with useCallback40renderItem={({ item }) => <ItemCard item={item} />}41keyExtractor={(item) => item.id}42estimatedItemSize={80}43/>44)45}46// Only ~10-15 visible items mounted at a time47```4849**Alternative (FlashList):**5051```tsx52import { FlashList } from '@shopify/flash-list'5354function Feed({ items }: { items: Item[] }) {55return (56<FlashList57data={items}58// if you aren't using React Compiler, wrap these with useCallback59renderItem={({ item }) => <ItemCard item={item} />}60keyExtractor={(item) => item.id}61/>62)63}64```6566Benefits apply to any screen with scrollable content—profiles, settings, feeds,67search results. Default to virtualization.68