question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

Getting the below warning when I use FlatList and where keyExtractor returns a number.

Warning: Failed child context type: Invalid child context `virtualizedCell.cellKey` of type `number` supplied to `CellRenderer`, expected `string`.
    in CellRenderer (created by VirtualizedList)
    in RCTScrollContentView (created by ScrollView)
    in RCTScrollView (created by ScrollView)
    in ScrollView (created by VirtualizedList)
    in VirtualizedList (created by FlatList)

Sample Code for reproduction

import React, { Component } from 'react';
import { Text, View, FlatList } from 'react-native';

export default class NotificationSettingsScreen extends Component {
  render() {
    return (
      <View style={{flex: 1, paddingTop: 36}}>
        <FlatList
          data={[1, 2, 3, 4, 5]}
          renderItem={({item}) => (
            <View>
              <Text>{item}</Text>
            </View>
          )}
          keyExtractor={(item) => item }
        />
      </View>
    );
  }
}

NOTE: Changing keyExtractor={(item) => item.toString()} makes this warning disappear.

Environment

React-Native: 0.53.0, react: 16.2.0

Expected Behavior

keyExtractor of FlatList must accept number instead of just string

Actual Behavior

Warning when using keyExtractor which returns number

Steps to Reproduce

Check above lines

The above problem could also be due to this commit https://github.com/facebook/react-native/commit/a010a0cebd4afc0d88336c2c265a5d9dbb19918f but not sure …

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:94
  • Comments:15 (2 by maintainers)

github_iconTop GitHub Comments

182reactions
rfwcommented, May 12, 2018

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

The value of keyExtractor must be a string。

14reactions
hramoscommented, Mar 9, 2018

The prop expects a string but you’re setting a number. This seems to be working as expected.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid child context 'virtualizedCell.cellKey' of type 'number ...
To fix the error in any list components where a keyExtractor is in use, update the Component (FlatList etc) to have a string...
Read more >
Invalid child context `virtualizedCell.cellKey` of type `number`
Warning : Failed child context type: Invalid child context `virtualizedCell.cellKey` of type `number` supplied to `CellRenderer`, expected `string`.
Read more >
Invalid child context 'virtualizedCell.cellKey' of type 'number ...
Warning : Failed child context type: Invalid child context ... cellKey' of type 'number' supplied to 'CellRenderer', expected 'string'.
Read more >
Invalid child context 'virtualizedCell.cellKey' of type - YouTube
iOS : Warning : Failed child context type : Invalid child context ... of type ' number ' supplied to ' CellRenderer ',...
Read more >
Invalid child context 'virtualizedCell.cellKey' Solve Error in ...
cellKey ' of type 'number' supplied to 'CellRenderer', expected 'string' is ... React Native Warning Failed child context type: Invalid child ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found