Dan
Dan

Reputation: 8794

Invariant Violation: A VirtualizedList contains a cell which itself contains more than one VirtualizedList

The complete error is:

Invariant Violation: A VirtualizedList contains a cell which itself contains more than one VirtualizedList of the same orientation as the parent list. You must pass a unique listKey prop to each sibling list.

Every single one of my FlatList components has a keyExtractor prop. Every item within the List from react-native-elements component has a key prop.

Could anyone shed any light on the meaning of this problem?

Upvotes: 21

Views: 19868

Answers (7)

Vishal Parmar
Vishal Parmar

Reputation: 31

Simply do this:

<FlatList 
  data={[{name: 'a'}, {name: 'b'}]} 
  renderItem={
    ({item}) => <Text>{item.name}</Text>
  } 
  keyExtractor={(item, index) => index.toString()}
  listKey="YourListName" //put here list name
/>

Upvotes: 1

Prasad G Kulkarni
Prasad G Kulkarni

Reputation: 141

For nestedFlatList you need to add listKey property

Upvotes: 0

M.Daniyal Aslam
M.Daniyal Aslam

Reputation: 517

Use ListKey and keyExtractor props in the FlatList to prevent this error OR warning

Example :

  listKey={(item, index) => `_key${index.toString()}`}
  keyExtractor={(item, index) => `_key${index.toString()}`}

Upvotes: 9

A Adak
A Adak

Reputation: 19

I got this error. But fixed using unique string

listKey={moment().valueOf().toString()}

Upvotes: 0

Rana
Rana

Reputation: 126

if you are using FaltList as a nested list of any other FlatList or SectionList then you have to pass a unique value to this props listKey

listKey={this._keyExtractor}

_keyExtractor = (item, index) => {
return this.props.index+"_"+index+'_'+item.id+"_"+moment().valueOf().toString(); 
}

Upvotes: 3

Akila K Gunawardhana
Akila K Gunawardhana

Reputation: 251

I got this error when using nested flat lists.I use listKey instead of keyExtractor.

**listKey={(item, index) => 'D' + index.toString()}**

Upvotes: 14

Andrada L
Andrada L

Reputation: 276

As the error says "You must pass a unique listKey prop to each sibling list." A prop like listKey="someUniqueString" to FlatList fixed this error for me

Upvotes: 16

Related Questions