I have a json from an api response as below:
centres = [{
id: 1,
name: "DEF",
},{
id: 2,
name: "ABC",
}]
Now I want to populate that above data in a FlatList
return(
<View>
<FlatList
data={this.state.centres}
renderItem={({item}) => <CentreComponent centre={item}/>}
/>
</View>
);
But I cant do the above as the data (centres) doesnt have a "key" property.
Now I can loop through each item in the array and add a property "key" which has the same value as ID. But I find this in efficient.
Is there a better way to map "id" column to "key" to render the FlatList