Socket
Socket
Sign inDemoInstall

react-quiz-stepper

Package Overview
Dependencies
5
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-quiz-stepper

A react component that provides handy access of quiz data combined with a stepper.


Version published
Weekly downloads
0
Maintainers
1
Created
Weekly downloads
 

Readme

Source

react-quiz-stepper is a react component that gives handy access to quiz data combined with stepper. Behind the scenes it uses context api, so data can be accessed at any level in component tree. Most basic hooks are useQuiz and useStepper.

Install

npm i react-quiz-stepper

Features

  • Ready to use quiz builder with stepper component
  • Multi language
  • Supports multi choice
  • Report generation

Quick Start

Wrap your app inside QuizProvider. (It asks for questions array to initialize with.) and don't forget to import css file.

import React from 'react';
import { QuizProvider } from 'react-quiz-stepper';
import 'react-quiz-stepper/dist/index.css';

const questions = [];

function App() {
  return (
    <QuizProvider questions={questions}>
      {/* rest of your code here */}
    </QuizProvider>
  );
}
export default App;

Now create your Stepper component and put it inside QuizProvider.

import React from 'react';
import { Stepper, useQuiz } from 'react-quiz-stepper'

function QuizStepperDemo () {
  const { state } = useQuiz()

  return (
    <Stepper>
      {state.questions.map((question) => ...)}
      {
        /**
        * map through all questions and render
        * appropriate input
        * (multi choice or single choice based on question.type)
        * only one question will be active depending on the step value
        */
      }
    </Stepper>
  )
}

export default App

Using useQuiz

const { state, dispatch, getQuestion, getSavedAnswer, generateReport } =
  useQuiz();
NameTypeDescription
stateQuizStatecontains user info, user inputs and questions data.
dispatchReact.DispatchsaveUser: (payload: User) => void
saveQuestionAnswer: (payload: UserInput)
getSavedAnswerfunc(questionId) => number or number[] or ""
getQuestionfunc(questionId: number) => SimplifiedQuestion
generateReportfunc() => ReportState

Using useStepper

const { step, handleNext, handleBack, goToStep, isLastStep } = useStepper();
NameTypeDescription
stepnumberIndex of the active question.
handleNextVoidFunctionRenders next question on screen.
handleBackVoidFunctionRenders previous question on screen.
goToStepfunc(index: number) => void
goes to specific question provided.
isLastStepbooleanchecks if it is a last step.

It is possible to bind handleBack and handleNext to on click event, to go to next previous and next question respectively.

Keywords

FAQs

Last updated on 15 Apr 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc