Add useEffect hooks for state management in QuizRunner

This commit is contained in:
2026-01-08 02:04:16 +01:00
parent 336c899625
commit d107139d6c

View File

@@ -418,6 +418,32 @@ export default function QuizRunner({ defaultMode = 'all', defaultEntryId, autoSt
const correctText = deriveCorrectText(currentQuestion); const correctText = deriveCorrectText(currentQuestion);
const shouldShowExplanation = showResult && (!lastCorrect || showExplanation); const shouldShowExplanation = showResult && (!lastCorrect || showExplanation);
useEffect(() => {
if (status !== 'running') return;
const saved = history[currentIndex];
if (saved) {
setResponse(saved.response);
setShowResult(true);
setLastCorrect(saved.correct);
setLastSkipped(saved.skipped);
setShowExplanation(saved.showExplanation);
} else {
resetQuestionState();
}
}, [currentIndex, history, status]);
useEffect(() => {
if (!showResult) return;
setHistory((prev) => {
const next = [...prev];
const existing = next[currentIndex];
if (existing) {
next[currentIndex] = { ...existing, showExplanation };
}
return next;
});
}, [showExplanation, showResult, currentIndex]);
return ( return (
<div className="quiz-runner"> <div className="quiz-runner">
<div className="quiz-top"> <div className="quiz-top">