I want to call my local API with this 'http://localhost:8080/profile?id=1' but its error like TypeError : Network request failed.
This is my code and i want to call my local API
import React, { useState, useEffect } from 'react';
import { View, Text, Button } from 'react-native';
import { FlatList } from 'react-native-gesture-handler';
import styles from '../style/Event.style';
const URL = "http://localhost:8080/profile?id=1"
const Event = ({ navigation }) => {
const [data, setData] = useState([])
useEffect(() => {
fetch(URL)
.then((response) => response.json())
.then((json) => setData(json.data))
.catch((error) => alert(error))
})
return (
<View style={styles.container}>
<FlatList
data={data}
renderItem={({ item }) => (
<Text>{item.name}</Text>
)}
keyExtractor={(item, index) => index.toString()}
/>
<Text>{data.name}</Text>
</View>
);
};
export default Event;
Anyone know how can i do to make a call with local API?