forked from caike/React-QuizComponent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuiz.js
More file actions
33 lines (30 loc) · 894 Bytes
/
Copy pathQuiz.js
File metadata and controls
33 lines (30 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import React, { Component } from 'react'
import QuizQuestion from './QuizQuestion'
import QuizEnd from './QuizEnd'
let quizData = require('./quiz_data.json')
class Quiz extends Component {
constructor(props) {
super(props)
this.state = { quiz_position: 1 }
}
showNextQuestion() {
this.setState((state) => {
return {quiz_position: state.quiz_position + 1}
})
}
handleResetClick() {
this.setState({ quiz_position: 1 })
}
render() {
const isQuizEnd = (this.state.quiz_position - 1) === quizData.quiz_questions.length
return (
<div>
{isQuizEnd ?
<QuizEnd resetClickHandler={this.handleResetClick.bind(this)} /> :
<QuizQuestion quiz_question={quizData.quiz_questions[this.state.quiz_position - 1]} showNextQuestionHandler={this.showNextQuestion.bind(this)} />
}
</div>
)
}
}
export default Quiz