91

I updgraded from react 16.2 -> 16.3-alpha-1 and react-native 0.52->0.54 and I get the warning above in the simulator.

dhj
  • 4,780
  • 5
  • 20
  • 41
  • 2
    I wasn't even using the keyExtractor property, and I got this warning anyway. Had to add this garbage noise to my code to avoid the warning. Bad API. – Andrew Koster Oct 22 '19 at 02:42

3 Answers3

289

To fix the error in any list components where a keyExtractor is in use, update the Component (FlatList etc) to have a string key with .toString(). All keys must now be string values.

Like below;

keyExtractor={item => item.index_id}

to

keyExtractor={item => item.index_id.toString()}

This change is a requirement for all uses of a keyExtractor so that would include React-Native components like; FlatList and ActionSheet.

dhj
  • 4,780
  • 5
  • 20
  • 41
6
keyExtractor={(item, index) => index.toString()}

This will solve the warning given by React and React Native.

Aun Abbas
  • 540
  • 7
  • 18
  • 1
    I'm always appreciative of answers that can silence a warning without changing behavior while also working in every case – ICW Jun 11 '21 at 16:37
  • 1
    Do note that using an array index as the key for a component is a bad practice and is discouraged by the React docs (except that there's absolutely no other choice) See more here https://reactjs.org/docs/lists-and-keys.html – Geropellicer Jul 13 '21 at 19:17
-2

You could try this solution:

keyExtractor={(item, index) => item + index.toString()}
Just Mohit
  • 141
  • 1
  • 13
Mirza Hayat
  • 284
  • 5
  • 11