You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found out section list invokes renderItem method for all the items even if there are not visible in the screen.
Here's the expo snack link: https://snack.expo.dev/7cjOb_kzYa8_8gcuW9i9s
If anyone can help understand why is it happening?
This is the basic code snippet
importReactfrom'react';import{View,Text,SectionList,StyleSheet,SafeAreaView}from'react-native';constGroceryInventory=()=>{constgroceryData=[{title: 'Fruits',data: Array(50).fill(2).map((_,index)=>({id: `fruit-${index}`,name: `Fruit ${index}`,price: `$${(Math.random()*5).toFixed(2)}`}))},{title: 'Vegetables',data: Array(50).fill(2).map((_,index)=>({id: `vegetable-${index}`,name: `Vegetable ${index}`,price: `$${(Math.random()*5).toFixed(2)}`}))},{title: 'Dairy',data: Array(50).fill(2).map((_,index)=>({id: `dairy-${index}`,name: `Dairy ${index}`,price: `$${(Math.random()*5).toFixed(2)}`}))}];constrenderSectionHeader=({section: { title }})=>{console.log("RENDERING SECTION",title);return(<Viewstyle={styles.sectionHeader}><Textstyle={styles.sectionHeaderText}>{title}</Text></View>)};constrenderItem=({ item })=>{console.log("RENERING ITEEEM",item);return(<Viewstyle={styles.item}><Textstyle={styles.itemName}>{item.name}</Text><Textstyle={styles.itemPrice}>{item.price}</Text></View>)};return(<SafeAreaViewstyle={styles.container}><SectionListsections={groceryData}keyExtractor={(item)=>item.id}renderSectionHeader={renderSectionHeader}renderItem={renderItem}// Performance optimization propsinitialNumToRender={10}// Initially render 10 itemsmaxToRenderPerBatch={10}// Render 10 items per batchwindowSize={21}// Render items just outside of visible area// Optional: Improve performance with these additional propsremoveClippedSubviews={true}// Unmount components when outside of window updateCellsBatchingPeriod={50}// Increase time between batch renderslistKey="grocery-section-list"// Optional scroll performance improvementsgetItemLayout={(data,index)=>({length: 50,// Assuming a fixed item heightoffset: 50*index,
index,})}/></SafeAreaView>);};conststyles=StyleSheet.create({container: {flex: 1,backgroundColor: '#f5f5f5'},sectionHeader: {backgroundColor: '#e1e1e1',padding: 10,},sectionHeaderText: {fontSize: 18,fontWeight: 'bold',},item: {flexDirection: 'row',justifyContent: 'space-between',padding: 15,borderBottomWidth: 1,borderBottomColor: '#ddd',},itemName: {fontSize: 16,},itemPrice: {fontSize: 16,color: '#888',}});exportdefaultGroceryInventory;
Here's the output logs.
Steps to reproduce
Create a basic react native project with or without framework. Copy and paste the above code or just run the expo snack.
React Native Version
0.76.5
Affected Platforms
Runtime - iOS
Output of npx react-native info
info Fetching system and libraries information...
System:
OS: macOS 15.0
CPU: (10) arm64 Apple M1 Pro
Memory: 132.58 MB / 16.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 20.12.2
path: /usr/local/bin/node
Yarn:
version: 1.22.22
path: /usr/local/bin/yarn
npm:
version: 10.5.0
path: /usr/local/bin/npm
Watchman:
version: 2024.12.02.00
path: /opt/homebrew/bin/watchman
Managers:
CocoaPods:
version: 1.15.2
path: /opt/homebrew/lib/ruby/gems/3.1.0/bin/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 24.0
- iOS 18.0
- macOS 15.0
- tvOS 18.0
- visionOS 2.0
- watchOS 11.0
Android SDK: Not Found
IDEs:
Android Studio: 2024.1 AI-241.19072.14.2412.12360217
Xcode:
version: 16.0/16A242d
path: /usr/bin/xcodebuild
Languages:
Java:
version: 17.0.11
path: /usr/bin/javac
Ruby:
version: 3.1.5
path: /opt/homebrew/opt/[email protected]/bin/ruby
npmPackages:
"@react-native-community/cli":
installed: 15.1.3
wanted: latest
react:
installed: 18.3.1
wanted: 18.3.1
react-native:
installed: 0.76.5
wanted: 0.76.5
react-native-macos: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: Not found
newArchEnabled: Not found
iOS:
hermesEnabled: Not found
newArchEnabled: Not found
Description
I found out section list invokes
renderItem
method for all the items even if there are not visible in the screen.Here's the expo snack link: https://snack.expo.dev/7cjOb_kzYa8_8gcuW9i9s
If anyone can help understand why is it happening?
This is the basic code snippet
Here's the output logs.
Steps to reproduce
Create a basic react native project with or without framework. Copy and paste the above code or just run the expo snack.
React Native Version
0.76.5
Affected Platforms
Runtime - iOS
Output of
npx react-native info
Stacktrace or Logs
Reproducer
https://snack.expo.dev/7cjOb_kzYa8_8gcuW9i9s
Screenshots and Videos
No response
The text was updated successfully, but these errors were encountered: