let members: IMember[] = []
const urlGetMemberList = 'http://localhost:8080/member/getStudentList'
export const MemberList = ({navigation}) => {
const [datas, setDatas] = useState(null);
const [loading, setLoading] = useState(false);
const [error, setError] = useState(null);
useFocusEffect(React.useCallback(() => {
const fetchDatas = async () => {
try {
setError(null);
setDatas(null);
setLoading(true);
console.log("call axios")
const response = await axios.get(urlGetMemberList);
setDatas(response.data);
} catch (e: any) {
setError(e);
}
setLoading(false);
};
fetchDatas();
}, []))
console.log(datas)
if(datas != null) {
members = []
console.log(datas.responseBody.length)
for(let idx = 0; idx < datas.responseBody.length; idx++) {
members.push(new Member(idx, datas.responseBody.name, datas.responseBody.phone, datas.responseBody.startDate, datas.responseBody.remainCount))
}
}
const renderItem = (item: IMember) => {
return (
<TouchableOpacity
onPress={() => {
Alert.alert(item.name)
navigation.navigate('borderScreen')
}}
>
<RenderMember member={item} />
</TouchableOpacity>
)
}
return (
<SafeAreaView>
<FlatList data={members}
renderItem={({item}) => renderItem(item)}
keyExtractor={(item, index) => item.id.toString()}
ItemSeparatorComponent={() => <View style={[styles.itemSeprator]} />}
/>
</SafeAreaView>
)
}