A quiz app built with React and The Trivia API. Pick a category, difficulty and number of questions, answer them, then see how you did.
Do whatever you like with it: fork it, copy bits out of it, or use it as the starting point for your own quiz. It's MIT licensed.
You'll need Node 20.19 or later.
npm install
npm run devThen open http://localhost:5173. No API key needed.
Other scripts:
npm testruns the testsnpm run buildbuilds the app intodist/npm run lintlints with oxlint
The questions come from The Trivia API through @trivia-api/sdk, which gives you typed functions for every endpoint.
src/api.tsfetches the questions, and turns errors into something a player can read (e.g. when you hit the rate limit)src/App.tsxholds the state of the game: setting up, loading, playing, finished or erroredsrc/shuffle.tsmixes the correct answer in with the incorrect ones, without biassrc/components/has one component per screen
Styling is plain CSS in src/index.css. The colours are custom properties at the top, so changing those restyles the whole app.
The tests in src/App.test.tsx mock the SDK, so they never call the real API. That's probably the pattern to copy if you add your own.
Some ideas if you want to build on it:
- Filtering by tag (e.g.
tags: "dinosaurs") for themed quizzes - Text input questions, where players type the answer (
types: "text_input") andvalidateQuestionAnswerchecks it, accepting small differences like plurals - Sessions, so players never see the same question twice
The last two need an API key.
The API docs cover everything else.
The Trivia API is free for non-commercial projects. For anything commercial you'll need a subscription.