1const Dashboard = () => {
2 const [data, setData] = useState([]);
3 const [loading, setLoading] = useState(true);
4
5 useEffect(() => {
6 const fetchData = async () => {
7 try {
8 const response = await fetch('/api/dashboard-stats');
9 const result = await response.json();
10 setData(result);
11 setLoading(false);
12 } catch (error) {
13 console.error("Failed to fetch dashboard data:", error);
14 setLoading(false);
15 }
16 };
17
18 fetchData();
19 }, []);
20};