I'm new to react-native I'm writing an app flat list contains cards but I get this error here is my code
constructor (props) {
super(props);
this.state = {
GridListItems: [ // Home Screen Cards Data [STATIC]
{ id: 1 , key: "222" , img: 'https://i.ibb.co/Lt88dTg/makeup.png' },
{ id: 2 ,key: "2" , img: 'https://i.ibb.co/H4NRnZK/Photographers.png'},
{ id: 3 ,key: "Wedding Halls" , img: 'https://i.ibb.co/b2JdtHW/wedding-Hall.png'},
{ id: 4 ,key: "Wedding Planners" , img: 'https://i.ibb.co/g95HhKT/image-1.jpg'},
{ id: 5 ,key: "Ateliers for Dresses" , img: 'https://i.ibb.co/g4ksBDk/wedding.png'},
]
};
}
renderItem = ({item}) => {
return(
<TouchableOpacity key={item.id.toString()}
style={styles.GridViewContainer}
>
</TouchableOpacity>
)
}
render () {
const carousel = this.mainCarousel(1); // Rendering the Carousel
return (
<SafeAreaView style={styles.safeArea}>
{ this.gradient }
<ScrollView
style={styles.scrollview}
scrollEventThrottle={200}
directionalLockEnabled={true}
>
{/* { carousel } */}
<FlatList
data={ this.state.GridListItems }
keyExtractor={(item) => item.id.toString()}
renderItem={ this.renderItem }
numColumns={2}
initialNumToRender={6}
/>
</ScrollView>
</SafeAreaView>
);
}
but I get Warning: Each child in a list should have a unique "key" prop. See https://fb .me/ react-warning-keys for more information.%s,
what am I doing wrong here?
.map()
or any other iterating function inside of a render function? The warning should tell you which component causes the issue – Auskennfuchs