import React, { useEffect, useState } from 'react'; interface QuizModule { questionId: string; questionText: string; option1: string; option2: string; option3: string; option4: string; correctAnswer: string; moduleId: string; } export default function AdminIndex() { const [questionList, setQuestionList] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { fetch(`http://localhost:5174/api/question-list`) .then(res => { if (!res.ok) { throw new Error('Network response was not ok'); } return res.json(); }) .then(data => { console.log(data); setQuestionList(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 (
{questionList.map(question => ( ))}
Question ID Question Option 1 Option 2 Option 3 Option 4 Correct Answer Module ID Action
{question.questionId} {question.questionText} {question.option1} {question.option2} {question.option3} {question.option4} {question.correctAnswer} {question.moduleId}
); }