Очевидно, я попробовал Localhost и 127.0.0.1, но ни один из них не работал для меня.
Код: Выделить всё
import { StatusBar } from 'expo-status-bar';
import React, { Component, useState, useEffect } from 'react';
import { StyleSheet, Text, View, FlatList, ActivityIndicator, Image } from 'react-native';
const API_ENDPOINT = "https://127.0.0.1:5001/api/Medicines/";
export default function App () {
const [isLoading, setIsLoading] = useState(false);
const [data, setData] = useState([]);
const [error, setError] = useState(null);
useEffect(() => {
setIsLoading(true);
fetch(API_ENDPOINT)
.then(response => response.json())
.then(results => {
setData(results);
setIsLoading(false);
})
.catch(err => {
setIsLoading(false);
setError(err);
});
}, []);
if (isLoading) {
return (
);
}
if (error) {
return (
Error fetching data... Check your network connection!
);
}
return (
Successful connection
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
Подробнее здесь: https://stackoverflow.com/questions/698 ... om-android