From 4a802100d16ee9f52e6e4caea6e54b9a49694351 Mon Sep 17 00:00:00 2001 From: Alex McKelvey Date: Tue, 24 Apr 2018 13:40:27 -0700 Subject: [PATCH] Improve VirtualizedList yellow-box warning when item is missing a key Reviewed By: sahrens Differential Revision: D7746659 fbshipit-source-id: b271dcd604d9adb85d0996dce5b8af1a6efd37d2 --- Libraries/Lists/VirtualizedList.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Libraries/Lists/VirtualizedList.js b/Libraries/Lists/VirtualizedList.js index 30e8777ea..bbfc6cf3b 100644 --- a/Libraries/Lists/VirtualizedList.js +++ b/Libraries/Lists/VirtualizedList.js @@ -218,6 +218,7 @@ type OptionalProps = { export type Props = RequiredProps & OptionalProps; let _usedIndexForKey = false; +let _keylessItemComponentName: string = ''; type Frame = { offset: number, @@ -431,6 +432,9 @@ class VirtualizedList extends React.PureComponent { return item.key; } _usedIndexForKey = true; + if (item.type && item.type.displayName) { + _keylessItemComponentName = item.type.displayName; + } return String(index); }, maxToRenderPerBatch: 10, @@ -762,6 +766,7 @@ class VirtualizedList extends React.PureComponent { const itemCount = this.props.getItemCount(data); if (itemCount > 0) { _usedIndexForKey = false; + _keylessItemComponentName = ''; const spacerKey = !horizontal ? 'height' : 'width'; const lastInitialIndex = this.props.initialScrollIndex ? -1 @@ -831,6 +836,7 @@ class VirtualizedList extends React.PureComponent { console.warn( 'VirtualizedList: missing keys for items, make sure to specify a key property on each ' + 'item or provide a custom keyExtractor.', + _keylessItemComponentName, ); this._hasWarned.keys = true; }