React Native - Use a keyExtractor with FlatList

i do this and work for me:

keyExtractor={(item, index) => 'key'+index}

"VirtualizedList: missing keys for items, make sure to specify a key property on an item or provide a custom keyExtractor"

This is a warning that the elements of the list are missing keys. These unique keys are what allow the VirtualizedList (which is what FlatList is built on) to track items and are really important in terms of efficiency.

You will have to choose a unique key prop, like an id or an email.

The keyExtractor falls back to using the index by default. But the warning will remain visible.

Example : an object defined as {key: doc.id, value: doc.data()} can be used in the extractor as:

keyExtractor={(item, index) => item.key}

Flatlist component should look like that:

<FlatList
  style={{}}
  data={this.state.FeedDataCollection}
  keyExtractor={(item, index) => item.key}
  renderItem={(rowData) =>this.RenderFeedCard(rowData)}
/>

The importance of this error is at the point where you start to change or delete any of the objects of your array because of how your list will get updated if you don't provide that key.

The way React Native deals with a change to your list without a key is to delete everything visible on the screen and then looks at the new array of data and renders a single element for each one.

We don't want React Native to rebuild an entire list just because of one small change to the array of data. Ideally, we want React Native to detect specifically the object we deleted or changed and update accordingly, but that will not happen if we do not provide the key.

The key property allows React Native to track these list of objects and that way it can keep track of what you are modifying or deleting and just delete that particular element with a particular key.

This way the list does not need to be rebuilt from scratch. The key will allow React Native to tie the definition of an object of data with some element that appears on the screen.

It's just allowing React Native to track the different list of objects we are rendering to the screen. It's also a performance optimization on making updates to our list.