React Quiz Component

Quiz component

Explore every prop accepted by the default Quiz component, including its types, defaults, and behavior. Configure feedback, navigation, timers, callbacks, and results, then learn how to restart a quiz and customize its styling.

import Quiz, { type QuizProps } from 'react-quiz-component';

Props

NameTypeDefaultRequiredDescription
quizQuizNoneYQuiz source object.
shufflebooleanfalseNShuffle questions before rendering.
shuffleAnswerbooleanfalseNShuffle answer choices before rendering.
showDefaultResultbooleantrueNShow the built-in result page when the quiz ends.
onComplete(summary: QuestionSummary) => voidundefinedNCalled once when the quiz completes.
customResultPage(summary: QuestionSummary) => React.ReactElementundefinedNRender a custom result page. Use with showDefaultResult={false}.
showInstantFeedbackbooleanfalseNShow correct or incorrect messages after answers are submitted.
showCorrectAnswerbooleanfalseNHighlight all correct choices after an evaluated immediate attempt. Deferred mode takes precedence.
continueTillCorrectbooleanfalseNFor single-answer questions, let the user keep trying until the correct answer is selected.
revealAnswerOnSubmitbooleanfalseNAllow editing selections and defer correctness feedback until the quiz completes.
allowNavigationbooleanfalseNShow previous and next controls so users can move between questions.
onQuestionSubmit(data: QuestionSubmitData) => voidundefinedNCalled when a question answer is submitted with the question, user answer, and correctness.
disableSynopsisbooleanfalseNSkip the landing page and start the quiz immediately.
timernumberundefinedNQuiz duration in seconds. Must be finite and at least 1.
questionTimernumberundefinedNTime budget per question in seconds, at least 1. Expiry locks the question and advances; the final expiry completes the quiz.
allowPauseTimerbooleanfalseNAllow pausing and resuming when timer or questionTimer is set.
allowQuitbooleanfalseNShow a confirmed Submit and quit action, including while paused, to finish with partial results.
enableProgressBarbooleanfalseNShow a progress bar above the quiz.

Results and restart

The default result page shows scores, explanations, correct answers, and filters for all, correct, incorrect, and unanswered questions. To supply your own result view, set showDefaultResult={false} and provide customResultPage. Set showDefaultResult={false} without a custom renderer to hide the result body while handling completion through onComplete. Supplying customResultPage while leaving showDefaultResult enabled suppresses both result bodies, so always pair the two props for custom results.

The default component has no reset prop. Change its React key to remount it and start a new session. Props that configure the engine are captured when a session is created.

See Quiz behavior for combinations, callbacks for payloads, and Locale for text overrides.

Server rendering

When disableSynopsis is combined with shuffle or shuffleAnswer, the component renders nothing on the server or during the first hydration render, then displays the prepared quiz after mounting. This prevents different server and browser random orders from causing hydration errors. Other configurations retain their server-rendered landing screen or unshuffled quiz. For custom headless interfaces, see Server rendering and shuffling.

Styling and themes

The default stylesheet is scoped to .react-quiz-container and loads when Quiz mounts. It uses the operating system's prefers-color-scheme setting for dark mode; it does not follow an application's .dark class automatically.

Wrap the component to scope overrides and give them enough specificity to override the lazy-loaded stylesheet:

<div className="my-quiz">
  <Quiz quiz={quiz} />
</div>;
.my-quiz .react-quiz-container {
  --quiz-max-width: 720px;
  --color-primary: #7c3aed;
  --color-primary-strong: #6d28d9;
  --color-primary-soft: #f5f3ff;
  margin: 0;
}

Use quiz.progressBarColor for a dedicated progress color. Use the headless API when you need complete control over components, styling or dialogs.

See Color tokens for the complete color reference, light and dark defaults, and theme override examples.

On this page