1.1.0 • Published 2 years ago

react-quiz-game v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

react-quiz-game

Beta version

NPM JavaScript Style Guide

Install

npm install --save react-quiz-game

Usage

import { Quiz } from 'react-quiz-game'

const questions = [
  {
    text: "2 + 4",
    answers: ["4", "6", "9", "10"],
    correctAnswer: "6",
  },
  {
    text: "3 + 2",
    answers: ["3", "5", "2", "1"],
    correctAnswer: "5",
  }
];

class Example extends Component {
  render() {
    return <Quiz 
      questions={questions}
      answersCallback={(quizResult) => { 'Your code here' }
    />
  }
}

Async Quiz

import { AsyncQuiz } from 'react-quiz-game'

const questions = [
  {
    id: "1",
    text: "2 + 4",
    answers: [
      { id: "6", label: "6" },
      { id: "2", label: "2" },
      { id: "1", label: "1" },
      { id: "-2", label: "-2" }
    ],
  },
  {
    id: "2",
    text: "10 - 7",
    answers: [
      { id: "3", label: "3" },
      { id: "2", label: "2" },
      { id: "17", label: "17" },
      { id: "0", label: "0" }
    ],
  }
];

const checkAnswer = async (aid, qid) => { //aid - answer id, qid = question id
    return await fetchResult(aid, qid);
    // { 
    //   value: true || false, 
    //   correctValue: { id, label } (optional)
    // }
  }

class Example extends Component {
  render() {
    return <AsyncQuiz 
      questions={questions}
      answersCallback={(quizResult) => { 'Your code here' }
      checkQuestion={checkAnswer}
    />
  }
}

License

MIT © TymchukRoman

1.1.0

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago