警告: 失败的子上下文类型: 提供给“ CellRenderer”的类型为“ number”的无效子上下文“ viralizedCell.cellKey”,预期为“ string”

我从条件反射16.2-> 16.3-alpha-1和条件反射原生0.52-> 0.54进行了升级,并且在模拟器中得到了上面的警告。

48151 次浏览

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.

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

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

You could try this solution:

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