import React, { useState, useEffect, useContext } from 'react'; import { Link } from 'react-router-dom'; import { UserContext } from '../context/UserContext'; import axios from 'axios'; import { Box, Typography, Grid2, Card, CardContent, CardMedia } from '@mui/material'; import defaultCharacterImage from '../assets/default-character.png'; const Profile = () => { const { userId, username } = useContext(UserContext); const [characters, setCharacters] = useState([]); useEffect(() => { const fetchCharacters = async () => { try { const response = await axios.get(`http://localhost:5000/games/${userId}/characters`); const charactersArray = Object.values(response.data); setCharacters(charactersArray); } catch (error) { console.error('Error fetching characters:', error); } }; if (userId) { fetchCharacters(); } }, [userId]); return ( Benutzerprofil: {username} Your Characters {characters.map((character) => ( {character.CharName} Race: {character.Race} Age: {character.Age} ))} ); }; export default Profile;