i have a flatlist in my app and loading data from json api. Now having this issue that i can not access id of a booking in flatlist keyExtractor. that is why nothing is showing in my flatlist.
Json file:
{
"success": true,
"data": {
"bookings": [
{
"id": 1,
"customer_id": 1,
"driver_id": 1,
"width": 1,
"height": 1
}
]
},
"message": "Current booking list"
}
i can access success like this : BookingData.success but i dont know how to pass "id" in keyExtractor to load data in flatlist.
<FlatList
data={BookingData}
renderItem={renderItem}
keyExtractor={(item, index) => item.data.bookings[index].id}
/>
right now flatlist is not showing any data.
>Solution :
You need to pass an array as data:
<FlatList
data={BookingData.data.bookings}
renderItem={renderItem}
/>
The keyExtractor prop is not needed, as FlatList checks if the items have an id attribute already.