Projects › Beginner
Quiz App in React
A timed multiple-choice quiz with categories, scoring, a review screen and a high-score table.
Level: Beginner · Time: 3–5 days · Tech stack: React, Vite, CSS
Features to build
- Pick a category and difficulty
- One question at a time with a 15-second timer
- Instant right/wrong feedback
- Result screen with review of every answer
- Top 5 scores saved locally
What you will learn
- React components and props
- useState, useEffect and timers
- Lifting state up
- Conditional rendering
Step-by-step guide
1. Set up
npm create vite@latest quiz -- --template react. Get questions from the free Open Trivia DB API or a local JSON file.
2. Model the game as states
'start' → 'playing' → 'result'. One status variable decides which screen to show.
const [status, setStatus] = useState('start');
const [index, setIndex] = useState(0);
const [answers, setAnswers] = useState([]);
3. The timer
useEffect(() => {
if (status !== 'playing') return;
const t = setTimeout(() => choose(null), 15000); // time's up
return () => clearTimeout(t); // clean up on every new question
}, [index, status]);
Always clean up timers in useEffect — a classic React bug.
4. Shuffle the options
Use the Fisher–Yates shuffle once per question (not on every render — compute it when questions load).
5. Score and review
Store each answer { question, chosen, correct }. The result screen maps over them and colours right/wrong.
6. High scores
Save { name, score, date } to localStorage, sort and keep the top 5.
Level it up
- Add a backend leaderboard
- Make questions from your own notes
- Add keyboard shortcuts (1–4)
On your resume
- Developed a React quiz app with timed questions, answer review and persistent high scores using hooks and the Open Trivia API.