androidreactjsreact-nativereact-flatlist

React Native FlatList keyExtractor "Item undefined" on Android


I have a simple FlatList that works when testing in the web browser, but on Android it gives an error

"TypeError: undefined is not an object (evaluating 'item.id')"

<FlatList       
    data={data}
    renderItem={renderItem}
    keyExtractor={item => item.id}
/>  

Putting a console log in the keyExtractor confirms that the item parameter is undefined, but only on Android. I've tried using the (item, index) => index.toString() as the extractor, the index parameter is correct but it also gives an error The data list is this

[
    {
        "id": 1,
        "name": "item1",
        "sku": "001",
        "price": 0,
        "quantity": 0
    }
]

Here's the render item function

const renderItem = ({item}) => {
    return <InventoryItem item={item}/>
};

Solution

  • Solved, the database connection uses slightly different syntax on Android than it does on web