How do I access the section index in the renderSectionHeader, without adding it to the…
- User
How do I access the section index in the renderSectionHeader, without adding it to the data?
<SafeAreaView style={{ flex: 1, backgroundColor: theme.colors.onPrimary }}> <SectionList showsVerticalScrollIndicator={false} style={{ margin: 10, marginBottom: 0 }} stickySectionHeadersEnabled={true} sections={foodData} keyExtractor={(item, index) => item + index} renderItem={({ item, index }) => { return ( ) }} renderSectionHeader={({ section: { title, index } }) => ( <> {console.log(index)} <Card.Title titleVariant={'headlineMedium'} style={[styles.titleContainer, { backgroundColor: theme.colors.onPrimary }]} title={title} right={(props) => index > 0 && } /> </> )} onRefresh={onRefresh} refreshing={refreshing}>
- Assistant
In a in React Native, the function provides access to the section object, but it doesn't include the index of the section automatically. To access the index of a section in , you will need to leverage the array in the component and pass the index information manually.