• Stars
    star
    366
  • Rank 116,547 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 6 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿ“™ React Quiz Component

react-quiz-component

๐Ÿ“™ React Quiz Component NPM version License Total NPM Download

react-quiz-component is a ReactJS component allowing users to attempt a quiz.

Features

  • JSON-based input
  • Quiz landing page showing title, synopsis and number of questions
  • Quiz Input Validator
  • Multiple answers with single correct answer
  • Multiple answers with multiple correct answers
  • Support text and photo answers
  • Continue till answered correctly
  • Show explainations when answered correctly or not
  • Quiz result page at the end with the dropdown filtering all questions or only those you answered correctly or incorrectly
  • Support custom result page
  • Return quiz summary at the page
  • Allow Instant feedback
  • Allow retry until the answer is selected correctly
  • Allow markdown in Question
  • Allow Picture in Question
  • Scoring System

Installing

npm i react-quiz-component

Importing react-quiz-component

import Quiz from 'react-quiz-component';

Defining Your Quiz Source

The quiz source is a JSON object. You can use react-quiz-form to generate it.

export const quiz =  {
  "quizTitle": "React Quiz Component Demo",
  "quizSynopsis": "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim",
  "nrOfQuestions": "4",
  "questions": [
    {
      "question": "How can you access the state of a component from inside of a member function?",
      "questionType": "text",
      "questionPic": "https://dummyimage.com/600x400/000/fff&text=X", // if you need to display Picture in Question
      "answerSelectionType": "single",
      "answers": [
        "this.getState()",
        "this.prototype.stateValue",
        "this.state",
        "this.values"
      ],
      "correctAnswer": "3",
      "messageForCorrectAnswer": "Correct answer. Good job.",
      "messageForIncorrectAnswer": "Incorrect answer. Please try again.",
      "explanation": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
      "point": "20"
    },
    {
      "question": "ReactJS is developed by _____?",
      "questionType": "text",
      "answerSelectionType": "single",
      "answers": [
        "Google Engineers",
        "Facebook Engineers"
      ],
      "correctAnswer": "2",
      "messageForCorrectAnswer": "Correct answer. Good job.",
      "messageForIncorrectAnswer": "Incorrect answer. Please try again.",
      "explanation": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
      "point": "20"
    },
    {
      "question": "ReactJS is an MVC based framework?",
      "questionType": "text",
      "answerSelectionType": "single",
      "answers": [
        "True",
        "False"
      ],
      "correctAnswer": "2",
      "messageForCorrectAnswer": "Correct answer. Good job.",
      "messageForIncorrectAnswer": "Incorrect answer. Please try again.",
      "explanation": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
      "point": "10"
    },
    {
      "question": "Which of the following concepts is/are key to ReactJS?",
      "questionType": "text",
      "answerSelectionType": "single",
      "answers": [
        "Component-oriented design",
        "Event delegation model",
        "Both of the above",
      ],
      "correctAnswer": "3",
      "messageForCorrectAnswer": "Correct answer. Good job.",
      "messageForIncorrectAnswer": "Incorrect answer. Please try again.",
      "explanation": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
      "point": "30"
    },
    {
      "question": "Lorem ipsum dolor sit amet, consectetur adipiscing elit,",
      "questionType": "photo",
      "answerSelectionType": "single",
      "answers": [
        "https://dummyimage.com/600x400/000/fff&text=A",
        "https://dummyimage.com/600x400/000/fff&text=B",
        "https://dummyimage.com/600x400/000/fff&text=C",
        "https://dummyimage.com/600x400/000/fff&text=D"
      ],
      "correctAnswer": "1",
      "messageForCorrectAnswer": "Correct answer. Good job.",
      "messageForIncorrectAnswer": "Incorrect answer. Please try again.",
      "explanation": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
      "point": "20"
    },
    {
      "question": "What are the advantages of React JS?",
      "questionType": "text",
      "answerSelectionType": "multiple",
      "answers": [
        "React can be used on client and as well as server side too",
        "Using React increases readability and makes maintainability easier. Component, Data patterns improves readability and thus makes it easier for manitaining larger apps",
        "React components have lifecycle events that fall into State/Property Updates",
        "React can be used with any other framework (Backbone.js, Angular.js) as it is only a view layer"
      ],
      "correctAnswer": [1, 2, 4],
      "messageForCorrectAnswer": "Correct answer. Good job.",
      "messageForIncorrectAnswer": "Incorrect answer. Please try again.",
      "explanation": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
      "point": "20"
    },
  ]
} 

Locale Customization

If you want to use your customized text, you can add appLocale into your quiz source. Below is the default one. and will be replaced dynamically.

 "appLocale": {
    "landingHeaderText": "<questionLength> Questions",
    "question": "Question",
    "startQuizBtn": "Start Quiz",
    "resultFilterAll": "All",
    "resultFilterCorrect": "Correct",
    "resultFilterIncorrect": "Incorrect",
    "prevQuestionBtn": "Prev",
    "nextQuestionBtn": "Next",
    "resultPageHeaderText": "You have completed the quiz. You got <correctIndexLength> out of <questionLength> questions."
  } 

Passing to Quiz container

 import { quiz } from './quiz';
 ...
 <Quiz quiz={quiz}/>

Shuffling question set

 import { quiz } from './quiz';
 ...
 <Quiz quiz={quiz} shuffle={true}/>

Disabling Default Result Page

 import { quiz } from './quiz';
 ...
 <Quiz quiz={quiz} showDefaultResult={false}/>

Enabling Custom Result Page

  • In order to enable custom result page, showDefaultResult has to be false.
 import { quiz } from './quiz';
 ...
  const renderCustomResultPage = (obj) => {
    console.log(obj);
    return (
      <div>
        This is a custom result page. You can use obj to render your custom result page
      </div>
    )
  }
 ...
  <Quiz quiz={quiz} showDefaultResult={false} customResultPage={renderCustomResultPage}/>

Enabling onComplete Action

 import { quiz } from './quiz';
 ...
  const setQuizResult = (obj) => {
    console.log(obj);
    // YOUR LOGIC GOES HERE
  }
 ...
  <Quiz quiz={quiz} showDefaultResult={false} onComplete={setQuizResult}/>

Example of Quiz Summary returned to customResultPage and onComplete

Object
  numberOfCorrectAnswers: 4
  numberOfIncorrectAnswers: 1
  numberOfQuestions: 5
  questions: Array(5)
    0: {question: "Which of the following concepts is/are key to ReactJS?", questionType: "text", answers: Array(3), correctAnswer: "3", messageForCorrectAnswer: "Correct answer. Good job.", โ€ฆ}
    1: {question: "ReactJS is developed by _____?", questionType: "text", answers: Array(2), correctAnswer: "2", messageForCorrectAnswer: "Correct answer. Good job.", โ€ฆ}
    2: {question: "How can you access the state of a component from inside of a member function?", questionType: "text", answers: Array(4), correctAnswer: "3", messageForCorrectAnswer: "Correct answer. Good job.", โ€ฆ}
    3: {question: "Lorem ipsum dolor sit amet, consectetur adipiscing elit,", questionType: "photo", answers: Array(4), correctAnswer: "1", messageForCorrectAnswer: "Correct answer. Good job.", โ€ฆ}
    4: {question: "ReactJS is an MVC based framework?", questionType: "text", answers: Array(2), correctAnswer: "2", messageForCorrectAnswer: "Correct answer. Good job.", โ€ฆ}
  userInput: (5) [1, 2, 1, 2, 3]
  totalPoints: 100
  correctPoints: 40

Showing Instant Feedback

 import { quiz } from './quiz';
 ...
  <Quiz quiz={quiz} showInstantFeedback={true}/>

Answering the same question till it is correct

 import { quiz } from './quiz';
 ...
  <Quiz quiz={quiz} continueTillCorrect={true}/>

Props

Name Type Default Required Description
quiz object null Y Quiz Json Object
shuffle boolean false N Shuffle the questions
showDefaultResult boolean true N Show the default result page
customResultPage function null N A quiz summary object will be returned to the function and users can use it to render its custom result page
onComplete function null N A quiz summary object will be returned to the function
showInstantFeedback boolean false N Show instant feedback when it is true
continueTillCorrect boolean false N Continue to select an answer until it is correct
onQuestionSubmit function null N A user response for a question will be returned
disableSynopsis boolean false N Disable synopsis before quiz

Contribution

  • Clone the repository
  • Run npm install
  • Run npm run dev
  • Run npm run lint
  • Make a PR to develop and describe the changes

Demo

The demo is available at https://wingkwong.github.io/react-quiz-component/

License

This project is licensed under the MIT License - see the LICENSE file for details

More Repositories

1

leetcode-the-hard-way

LeetCode The Hard Way - From Absolute Beginner to Quitter. Join Discord: https://discord.com/invite/Nqm4jJcyBf
JavaScript
859
star
2

geodesy

A Dart library for geodesic and trigonometric calculations working with points and paths
Dart
51
star
3

react-quiz-form

๐Ÿ“•โœ๏ธ A redux form for creating quizzes in React
JavaScript
38
star
4

hk-atm-locator

๐Ÿง ้ฆ™ๆธฏ่‡ชๅ‹•ๆซƒๅ“กๆฉŸๅฎšไฝๅ™จ ๐Ÿง Centralising Automated Teller Machine (ATM) Data in Hong Kong in a well-defined yet standardised format and display in a web portal for public use
JavaScript
17
star
5

competitive-programming

This repository contains my CP solutions (mostly written in C++) from different OJs and contest sites
C++
17
star
6

bootstrap-cli

๐Ÿ’ป A minimalistic CLI to bootstrap projects with different frameworks
Go
12
star
7

squirrel

:squirrel: A responsive expense tracker built with Django to help you manage your expenses ๐Ÿ’ธ๐Ÿ’ธ๐Ÿ’ธ
Python
11
star
8

rich_link_preview

A Rich Link Preview widget written in Dart generating a rich presentation of the given link from social meta tags
Dart
9
star
9

pyramid

JSON-based Business Rules Engine
JavaScript
8
star
10

dart_tel_input

A Dart widget for entering international telephone numbers with dropdown searching input countries
Dart
8
star
11

lazy-load-youtube-videos

Pure JavaScript library for optimizing the performance while loading multiple YouTube videos on the same page
JavaScript
7
star
12

jquery-chameleon

๐Ÿ“น A jQuery plugin to synchronize slide images with videos in JWPlayer 7, HTML5 or YouTube Player
JavaScript
7
star
13

aws-playground

My AWS Playground
Python
6
star
14

k8sgen

Generating Kubernetes Resource Configurations in an Interactive CLI
Go
5
star
15

gatsby-nocodb-graphql-boilerplate

Gatsby with NocoDB (GraphQL) boilerplate
TypeScript
5
star
16

mit-deep-learning

Collections of resources from MIT Introduction to Deep Learning (6.S191)
5
star
17

mass-repo-migrator

๐Ÿšš๐Ÿšš๐Ÿšš Migrate N git repositories from X to Y in just Z clicks
Shell
4
star
18

telegram-files-downloader

Download files from Telegram
Python
4
star
19

argocd-playground

Demonstrating how to setup Argo CD on a k3s cluster using arkade and k3d
Go
4
star
20

tensorflow-playground

TensorFlow Learning Notebooks
Jupyter Notebook
3
star
21

go-grpc-boilerplate

A gRPC microservice boilerplate written in Go
Go
3
star
22

hk-address-parser

The universal python library for Hong Kong Address Parser
Python
2
star
23

node-crypto-cli

CLI for the crypto module to encrypt / decrypt files in your machine
JavaScript
2
star
24

serverless-boilerplate

Serverless Boilerplate (APIGW + DynamoDB + Lambda)
JavaScript
2
star
25

aws-certified-developer-associate-bible

Summary of A CLOUD GURU course
2
star
26

gin-boilerplate

Gin Boilerplate with Standard Go Project Layout
Makefile
2
star
27

sc

Bash Alias Collection
Shell
2
star
28

hk-mtr-station-opening-hours-scraper

Scraping Hong Kong MTR Station Opening Hours
Python
2
star
29

kratos-playground

Kratos Playground
Go
2
star
30

golang-playground

My Golang Playground
Go
2
star
31

static-web-foo

HTML
2
star
32

wingkwong

2
star
33

sync-dependency-version

Synchronise dependency versions between repositories
TypeScript
2
star
34

qsharp-playground

My Q# Playground
Q#
1
star
35

tf-chatbot-api

๐Ÿ’ป A Tensorflow chatbot APIs provider built with Seq2Seq model
Python
1
star
36

jquery-noti5

๐Ÿ“’ jQuery notification plugin
JavaScript
1
star
37

crawl-youtube-videos-from-playlist

Crawling YouTube Videos from playlist using Youtube Data v3 API
JavaScript
1
star
38

airflow-playground

My Airflow Playground
Python
1
star
39

react-video-slide-sync

PowerPoint slides synchronzied with Video in ReactJS
JavaScript
1
star
40

burn

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ A web platform built with Vue for creating and sending self destructing messages to other people
Vue
1
star
41

go-cli-starter

Cobra Starter Template
Go
1
star
42

candy-or-medicine-classifier

Classify an image using TensorFlow with Inception v3 model to see if it is ๐Ÿฌ or ๐Ÿ’Š
Python
1
star
43

aws-sts-temp-cred

Request temporary credentials for a MFA-enabled AWS account or IAM user
Python
1
star
44

spoj

Migrated to https://github.com/wingkwong/competitive-programming
C++
1
star
45

traefik-playground

Demonstrating how to setup Traefik on a k3s cluster using arkade and k3d.
1
star
46

download-google-images-cli

A NodeJs CLI for downloading images from Google Search
1
star
47

brownstone

My Personal Website
CSS
1
star
48

azure-playground

My Azure Playground
1
star
49

self-driving-car

Building a self-driving car using Deep Q-Learning
Python
1
star
50

deno-playground

My Deno Playground
TypeScript
1
star
51

lxd-playground

My LXD Playground
Shell
1
star
52

tabify.js

jQuery plugin - Tabify your web content
JavaScript
1
star
53

nlp-playground

My NLP Playground
Python
1
star
54

skaffold-playground

My Skaffold Playground
Go
1
star
55

aws-sam-cicd-pipeline

Building a CI/CD Pipeline for a SAM Application written in Go with CodeCommit, CodeBuild, CodePipeline, CloudFormation and the AWS CDK.
TypeScript
1
star
56

gatsby-foo

TypeScript
1
star
57

ms-dynamics365-cti-connector

Microsoft Dynamics 365 CTI Connector
C#
1
star
58

sealed-secrets-example

Sealed Secrets Example
Dockerfile
1
star
59

gcp-playground

My GCP Playground
Python
1
star
60

gRPC-playground

My gRPC Playground
1
star
61

computer-vision-playground

Computer Vision Playground
Jupyter Notebook
1
star
62

pcsk

๐Ÿ“ฆ Python CLI Starter Kit
Python
1
star
63

machine-learning-cookbook

Learning Machine Learning
Jupyter Notebook
1
star
64

backpack

1
star