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?

Srishti Singhal picture Srishti Singhal · Oct 9, 2017 · Viewed 9.2k times · Source

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>

Answer

Vahid Boreiri picture Vahid Boreiri · Oct 9, 2017

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)}
     ...
   />