Skip to content

Commit

Permalink
Merge pull request #2 from nanlabs/feature/reset
Browse files Browse the repository at this point in the history
Feature/reset
  • Loading branch information
kerbaras authored Nov 6, 2020
2 parents 17c737f + 6bf813d commit 186ff1b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nanlabs/questionnaire",
"version": "1.0.12",
"version": "1.0.14",
"description": "Made with create-react-library",
"author": "Kupuka-D",
"license": "MIT",
Expand Down
20 changes: 19 additions & 1 deletion src/components/Questionnaire.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
import React, { useEffect } from 'react'
import { useStore } from '../Questionnaire/QuestionnaireContext'
import { changeQuestion } from '../utils/helpers'

export const Questionnaire = ({
children,
className,
dataProvider,
changeQuestionHandler
changeQuestionHandler,
reset
}) => {
const [, dispatch] = useStore()

const setFirstQuestion = () => {
const question = dataProvider.getQuestions()[0]
const next = dataProvider.getNextQuestion(question)
const prev = dataProvider.getPrevQuestion(question)
changeQuestion(question, dispatch, next, prev)
if (changeQuestionHandler) changeQuestionHandler(question)
}

useEffect(() => {
setFirstQuestion()
dispatch({
type: 'setCurrentSection',
payload: dataProvider.getSections()[0]
})
}, [reset, dispatch, dataProvider])

useEffect(() => {
dispatch({ type: 'setDataProvider', payload: dataProvider })
}, [dataProvider, dispatch])
Expand Down

0 comments on commit 186ff1b

Please sign in to comment.