I am using the same code in two different components. I got the error in react native code Encountered two children with the same key, 29270
. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version.
How I can solve this error I don't understand what is the error and why to occur please help me to solve the problem
<SafeAreaView style={styles.container}>
<FlatList data={this.state.dataSource}
renderItem={({item}) =>
<TouchableOpacity style={styles.item} onPress= {() =>this.props.navigation.replace('Test', { StudentUid: item1.uniquecode, AccessToken: this.state.accessToken })} >
<Text style={{fontSize:16, fontWeight:'bold'}}>{item.id} {item.firstname} {item.middlename} {item1.lastname}</Text>
</TouchableOpacity>
}
/>
</SafeAreaView>
can I use like this
<SafeAreaView style={styles.container}>
<FlatList data={this.state.dataSource}
renderItem={({item}) =>
<TouchableOpacity key={item.id} style={styles.item} onPress= {() =>this.props.navigation.replace('Test', { StudentUid: item1.uniquecode, AccessToken: this.state.accessToken })} >
<Text style={{fontSize:16, fontWeight:'bold'}}>{item.id} {item.firstname} {item.middlename} {item1.lastname}</Text>
</TouchableOpacity>
}
/>
</SafeAreaView>
Is this write code?