return ( <SafeAreaView style={{ flex: 1, backgroundColor: theme.colors.onPrimary }}>…
- User
return ( <SafeAreaView style={{ flex: 1, backgroundColor: theme.colors.onPrimary }}> <SectionList ref={sectionListRef} removeClippedSubviews={true} style={{ margin: 10 }} stickySectionHeadersEnabled={true} sections={foodData} keyExtractor={(item, index) => item + index} renderItem={({ item }) => { return ( <FoodPost onPress={() => { console.log(item.key); sectionListRef.current.scrollToLocation({ itemIndex: 6, }); }} data={item} /> ) }} renderSectionHeader={({ section: { title } }) => ( <Text style={[styles.titleContainer, { backgroundColor: theme.colors.onPrimary }]}>{title} )} onRefresh={onRefresh} refreshing={refreshing}> ); }
How do I scroll to the item index just clicked?
- Assistant
To scroll to the item index that you just clicked, you can utilize the
itemIndexin thesectionListRef.current.scrollToLocationmethod. You'll need to pass theindexof the clicked item to theonPresshandler of theFoodPost.Here's how you can do it:
- Pass the
indexof each item to the function.
- Pass the