import React, { useEffect, useState } from 'react'; interface QuizModule { quizName: string; quizId: string; totalQuestion: string; internalMarks: string; attendance: string; moduleId: string; } export default function AdminIndex() { const [quizList, setQuizList] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { fetch(`http://localhost:5174/api/quiz-list`) .then(res => { if (!res.ok) { throw new Error('Network response was not ok'); } return res.json(); }) .then(data => { console.log(data); setQuizList(data); setLoading(false); }) .catch(error => { console.error('An error occurred', error); setError(error); setLoading(false); }); }, []); // Dependency array to run the effect only once on mount if (loading) { return
Loading...
; } if (error) { return
Error: {error.message}
; } return (
{quizList.map(quiz => ( ))}
Quiz ID Quiz Name Total Question internalMarks Attendance Module ID Action
{quiz.quizId} {quiz.quizName} {quiz.totalQuestion} {quiz.internalMarks} {quiz.attendance} {quiz.moduleId}
); }