Home > Software engineering >  facing issue of unique key, while using map_ array
facing issue of unique key, while using map_ array

Time:05-21

    {multiList.map((item,index)=>
     <View style={{ flexDirection: "row" }}>
     <TouchableOpacity
       onPress={() => {}}
       style={styles.GridViewBlockStyle}
     >
       <Text style={styles.GridViewInsideTextItemStyle}>
         {item.key}
       </Text>
     </TouchableOpacity>
   </View>
    )}

error Warning: Each child in a list should have a unique "key" pro

CodePudding user response:

You needed to supply a key (a prop called 'key') to the component you are rendering.

<View 
   key={index}

CodePudding user response:

try this,

 {multiList.map((item,index)=>
     <View key={index} style={{ flexDirection: "row" }}> // pass unique key here
     <TouchableOpacity
       onPress={() => {}}
       style={styles.GridViewBlockStyle}
     >
       <Text style={styles.GridViewInsideTextItemStyle}>
         {item.key}
       </Text>
     </TouchableOpacity>
   </View>
    )}
  • Related