React-native ListView keys

后端 未结 2 1651
温柔的废话
温柔的废话 2020-12-17 22:05

I\'m getting a warning on my app that bothers me. the react keeps saying that I need to add key for each row, but no matter what I cannot add these keys.

my code loo

相关标签:
2条回答
  • 2020-12-17 22:40

    As stated by Gabriel Lopes in his comment, a common mistake is to forget to add keys to the separators.

    So make sure they are added. You can build them from the arguments passed to the separator function:

    renderSeparator(sectionId, rowId, adjacentRowHighlighted) {
      return (<View key={`sep:${sectionId}:${rowId}`} />);
    }
    
    0 讨论(0)
  • 2020-12-17 22:52

    Actually renderRow gets four arguments (rowData, sectionID, rowID, highlightRow) , and you need the third and not the second one.

    renderRow={(rowData, sectionID, rowID) => <Card key={rowID} data={rowData} 
                onPress={this.onCardPress.bind(this,rowData)} /> }
    

    Reference: facebook.github.io/react-native/docs/listview.html#renderrow

    0 讨论(0)
提交回复
热议问题