A lightweight, responsive quiz app built with React and Vite that fetches questions from the Open Trivia Database (OpenTDB). Designed for short, 5-question quizzes with randomized choices, score tracking, and a simple start/new game flow.
- Select quiz category and enter a player name.
- Fetches 5 multiple-choice questions from OpenTDB.
- Randomized answer order per question.
- Check answers to reveal correct/incorrect choices and display score.
- "New Game" flow to restart with fresh questions.
- Accessible, minimal UI and responsive layout.
- React (v18+)
- Vite
- nanoid (stable IDs)
- he (HTML entity decoding)
- react-icons
- CSS Modules
Prerequisites:
- Node.js 16+
- npm
Install and run locally:
npm install
npm run devBuild and preview:
npm run build
npm run previewLint:
npm run lint- Open the app in the browser (development server provided by Vite).
- Enter your name and choose a category on the Start screen.
- Click "Start Quiz" to fetch and display 5 questions.
- Select answers, then click "Check Answers" to reveal correct ones and see your score.
- Click "New Game" to play again with a new set of questions.
- index.html — App entry
- src/main.jsx — React bootstrap
- src/App.jsx — Top-level app and context provider
- src/Page/Start.jsx — Start screen (name & category)
- src/Page/Quiz.jsx — Quiz page wrapper
- src/components/QuizComp.jsx — Fetches questions and manages quiz state
- src/components/QuizList.jsx — Renders question list and score actions
- src/components/Question.jsx — Single question UI and answer styling
- src/components/UserData.jsx — Name & category form
- src/utils/HandleQuestionTypeContext.js — Category selection context
- vite.config.js — Vite configuration
- Category select passes values as "-"; parsing happens before API requests.
- Questions are retrieved from OpenTDB:
https://opentdb.com/api.php?amount=5&category=<id>. - HTML entities in questions/answers are decoded using
he.
- Fork the repository and create a feature branch.
- Run the app and tests locally, ensure linting passes.
- Open a pull request with a clear description of changes.
- If questions fail to load, confirm network access and that the OpenTDB API is reachable.
- Use the browser console or the dev server terminal to view runtime errors.
MIT License
Copyright (c) 2026 Your Name
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.