I'm trying to fetch data from my Django rest framework backend in react-native but keep getting this error when the app is started in expo. I can't see anything wrong with my function promise, maybe I'm looking at it the wrong way since am new to JavaScript's.
const HomeScreen = () => {
//const navigation = useNavigation()
const [data, setData] = useState([])
useEffect(() =>{
fetchData()
}, [])
const fetchData = async()=>{
const response = await fetch('http://127.0.0.1:8000/estate-list/')
const data = await response.json()
setData(data)
}
return (
<View style={styles.screen}>
<HomeList data={data} />
</View>
);
}
Home screen list component
const HomeList= ({data}) => {
const renderItem = ({item}) =>{
return <ListItem
price={item.price}
title={item.title}
description={item.description} />
}
return (
<View>
<FlatList
data={data}
keyExtractor={item => item.id}
renderItem={renderItem}
refreshControl={
<RefreshControl
refreshing= {false}
onRefresh={() => console.log("Refreshing.....!")} />
}
/>
</View>
);
}
ListItem component
const ListItem = ({ id, title, description,}) => {
const navigation = useNavigation()
return (
<TouchableOpacity style={styles.card}
onPress={() => navigation.navigate('Detail View',
{ eventId: id, title, description})}>
<Text>{title}</Text>
<Text>{description}</Text>
<Button title='More Info' color={'#0f172a'} />
</TouchableOpacity>
);
}