Warning : Failed child context type: Invalid child context 'virtualizedCell.cellKey' of type 'number' supplied to 'CellRenderer', expected 'string'

IosReactjsReact NativeExpo

Ios Problem Overview


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.

Ios Solutions


Solution 1 - Ios

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.

Solution 2 - Ios

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

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

Solution 3 - Ios

You could try this solution:

keyExtractor={(item, index) => item + index.toString()}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondhjView Question on Stackoverflow
Solution 1 - IosdhjView Answer on Stackoverflow
Solution 2 - IosAun AbbasView Answer on Stackoverflow
Solution 3 - IosMirza HayatView Answer on Stackoverflow