import React, { useState, useEffect } from 'react';
import { View, Text, FlatList, StyleSheet } from 'react-native';
const HospitalList = () => {
const [hospitals, setHospitals] = useState([]);
useEffect(() => {
fetch('http://hapi.codlook.com/hastaneler/')
.then(response => response.json())
.then(data => setHospitals(data))
.catch(error => console.error(error));
}, []);
const renderItem = ({ item }) => (
<View style={styles.item}>
<Text style={styles.title}>{item.hastane_adi}</Text>
<Text>{item.adres}</Text>
<Text>{item.telefon}</Text>
</View>
);
return (
<View style={styles.container}>
<FlatList
data={hospitals}
renderItem={renderItem}
keyExtractor={item => item.hastane_id}
/>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
marginTop: 20,
marginHorizontal: 16,
},
item: {
backgroundColor: '#f9c2ff',
padding: 20,
marginVertical: 8,
borderRadius: 10,
},
title: {
fontSize: 20,
fontWeight: 'bold',
},
});
export default HospitalList;