Quizzes are a powerful tool for education, training, and engagement. In this article, I’ll walk through how I built a QCM (Multiple-Choice Question) Quiz Generator using React, TypeScript, and styled-components, featuring:
✅ Light/Dark Mode Toggle
✅ Interactive Quiz Taking & Review
✅ JSON-Based Quiz Import/Export
✅ Responsive & Accessible Design
Let’s dive into the key features and technical decisions!
The app supports light/dark mode with a smooth transition effect. I used:
// ThemeContext.tsx
const toggleTheme = () => {
setMode((prev) => {
const newMode = prev === 'light' ? 'dark' : 'light';
localStorage.setItem('themeMode', newMode);
return newMode;
});
};
// Question.tsx
<OptionItem
$isCorrect={reviewMode && option.correct}
$isIncorrect={reviewMode && selectedOption === index && !option.correct}
>
{option.text}
{reviewMode && option.explanation && (
<ExplanationText>{option.explanation}</ExplanationText>
)}
</OptionItem>
Users can upload quizzes via JSON, making it easy to share and reuse question sets.
{
"title": "JavaScript Basics",
"questions": [
{
"question": "What is closure?",
"options": [
{ "text": "A function + its lexical scope", "correct": true },
{ "text": "A JavaScript class", "correct": false }
]
}
]
}
Defining strict types for quizzes and themes prevented runtime errors:
interface QuizData {
title: string;
questions: {
id: number;
question: string;
options: { text: string; correct: boolean }[];
}[];
}
Using CSS transitions and theme-aware components ensured a seamless UI experience.
/* GlobalStyles.ts */
* {
transition: background-color 0.3s ease, color 0.3s ease;
}
Flexible layouts with relative units (rem, %) and responsive padding made the app work on all devices.
You can check out the full code on GitHub or test the live demo here.
Would love to hear your feedback! What features would you add? 🚀
#React #TypeScript #WebDev #Frontend #QuizApp