I am creating an app with React Native
and I’ve used the map
method to show two items in an array.
But the warning keeps showing:
Each child in a list should have a unique "key" prop.
Here is my code:
<View>
{arrayType.map((item, key)=> {
return(
<>
<View key={item + key} style={customStyle.main}>
<Text>{item}</Text>
</View>
</>
)
})}
</View>
Why is it still showing that warning?
2
Answers
The parent component should consist key prop when rendering list in loop.
so code should look like this.
You are using a
React.Fragment
:<></>
.try this instead: