Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I have used FlatList and I want to get the rowId in the function which has been used to render items of list, how can I get that?

I have used this FlatList, where I have called renderRow function in which I have written code to render list Items, How can I get the rowId for each row renderer in renderRow method?

<List containerStyle={{borderTopWidth:0 , borderBottomWidth:0}}>
        <FlatList data={this.state.horseList}
        renderItem={(item) => this.renderRow(item)}
        _keyExtractor ={item => item.id} 
        onRefresh={this.handleRefresh}
        refreshing={this.state.refreshing}
        onEndReached={this.handleLoadMore}
        onEndReachedThreshold={1}
        ListFooterComponent={this.renderFooter}
        onRefresh={this.handleRefresh}
        />
    </List>
like image 800
Srishti Singhal Avatar asked Oct 09 '17 06:10

Srishti Singhal


1 Answers

If I understand your issue correctly, you can access the index of each row in this way:

   <FlatList data={this.state.horseList}
     ...
     renderItem={({item, index}) => this.renderRow(item, index)}
     ...
   />
like image 174
Vahid Boreiri Avatar answered Oct 05 '22 01:10

Vahid Boreiri