I am building a React Native app and having trouble with FlatList. I thought perhaps the problem was with the way I tried to implement this, so I used sample code from https://reactnative.dev/docs/flatlist and tried to run that by itself.
No matter how I try this, I am getting the error:
undefined is not an object (evaluating 'props.getItem')
This is generating from FlatList.js line 450.
Lines 449 and 450 from that file are:
_checkProps(props: Props<ItemT>) {
const {
This is from the FlatList.js that comes bundled with React Native.
I am on React Native 0.65.1.
Here is the code I am trying to run that is giving me the error:
import React from 'react';
import {
SafeAreaView,
View,
FlatList,
StyleSheet,
Text,
StatusBar,
} from 'react-native';
const DATA = [
{
id: 'bd7acbea-c1b1-46c2-aed5-3ad53abb28ba',
title: 'First Item',
},
{
id: '3ac68afc-c605-48d3-a4f8-fbd91aa97f63',
title: 'Second Item',
},
{
id: '58694a0f-3da1-471f-bd96-145571e29d72',
title: 'Third Item',
},
];
const Item = ({title}) => (
<View style={styles.item}>
<Text style={styles.title}>{title}</Text>
</View>
);
const ModalTrackSleep = () => {
const renderItem = ({item}) => <Item title={item.title} />;
return (
<SafeAreaView style={styles.container}>
<FlatList
data={DATA}
renderItem={renderItem}
keyExtractor={item => item.id}
/>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
marginTop: StatusBar.currentHeight || 0,
},
item: {
backgroundColor: '#f9c2ff',
padding: 20,
marginVertical: 8,
marginHorizontal: 16,
},
title: {
fontSize: 32,
},
});
export default ModalTrackSleep;
rm -rf node_modules
and run again your project – Braccirm -rf node_modules
did not help me; I'm having the same issue – Frangipane