'facing issue of unique key, while using map_ array
{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
Solution 1:[1]
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>
)}
Solution 2:[2]
You needed to supply a key (a prop called 'key') to the component you are rendering.
<View
key={index}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Shivam |
| Solution 2 | Harsh Patel |
