frontend/LikesScreen.js

40 lines
1002 B
JavaScript
Raw Permalink Normal View History

2024-02-08 14:10:53 +00:00
import React, { useEffect, useState } from 'react';
import { View, Text, FlatList } from 'react-native';
import { useAsyncStorage } from '@react-native-async-storage/async-storage';
const LikesScreen = ({ route }) => {
const { switId } = route.params;
const [likes, setLikes] = useState([]);
useEffect(() => {
fetchLikes();
}, []);
const fetchLikes = async () => {
const apiUrl = await AsyncStorage.getItem('apiEndpoint')
// replace with your server's address and correct route
const response = await fetch(`${apiUrl}/api/v1/app/swit/swits/${switId}/likes`, {
headers: {
Authorization: 'Bearer ' + token, // replace 'token' with the actual token
},
});
const data = await response.json();
setLikes(data);
};
return (
<View>
<FlatList
data={likes}
keyExtractor={(item) => item._id}
renderItem={({ item }) => <Text>{item.username}</Text>}
/>
</View>
);
};
export default LikesScreen;