Passa ai contenuti principali

Warning: Each child in an array or iterator should have a unique "key" prop.

Se qualcono di vuoi ha avuto a che fare con questo tipo di fastidioso warning in una FlatList, a partire da React Native 0.43.X, potete risolvere dichiarando una keyExtractor come segue:


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



 Nel mio caso, myID è una proprietà degli item che è univoca per ogni item:


<FlatList
          data={this.state.data}
          renderItem={({ item }) => (
            <ListItem
              onPress={() =>navigate('ShowPost', { user: 'Lucy' , content: 'my content'})}
              roundAvatar
              title={`${item.title.plaintext}`}
              subtitle="prova"
              avatar={{ uri:     "https://www.mywebsite/avatar.png" }}
              containerStyle={{ borderBottomWidth: 0 }}
            />
          )}
          keyExtractor={(item, index) => item.myID}
          ItemSeparatorComponent={this.renderSeparator}o
          ListHeaderComponent={this.renderHeader}
          ListFooterComponent={this.renderFooter}
          onRefresh={this.handleRefresh}
          refreshing={this.state.refreshing}
          onEndReached={this.handleLoadMore}
          onEndReachedThreshold={50}
        />
      </List>

Commenti