1. 程式人生 > >react native中陣列和key值

react native中陣列和key值

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

解決方法:在陣列名.map等迴圈子項中新增key屬性

array.map((value, index) => {
    return (
<View key={value.toString()}>//迴圈子項加key
        < DeviceView
img={require('../resources/images/ic_storage.png')}
            header={this.sdName[index
]} body={value} /> <View style={styles.itemDividerView}> <View style={styles.itemDivider}/> </View> </View> ) })