import { Card } from "@heroui/react"; import { useEffect, useState } from "react"; interface GuodegangData { name: string; content: string; } interface Props { topic: string; } export default function Guodegang({ topic }: Props) { const [data, setData] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { const fetchData = async () => { try { const response = await fetch( `http://localhost:8080/guodegang/${encodeURIComponent(topic)}`, ); if (!response.ok) { throw new Error("API Error"); } const result = await response.json(); setData(result.message); setError(null); } catch (error) { console.error("Failed to fetch data: ", error); setError("Failed to load data. Please try again."); } finally { setLoading(false); } }; fetchData(); }, [topic]); if (loading) { return (
Loading...
); } if (error) { return (
{error}
); } return (
🎤
{data!.name}

{data!.content}

); }