- Apply your Knowledgge
- Dealing with Effect Dependencies & Cleanup
- Combining Effects with Other React Concepts
- run
npm install
- run
npm run dev
- create a
README.md
- create a
components
folder - Inside it, add a
Header.jsx
component & aQuiz.jsx
component - built
Header.jsx
component - add states in
Quiz.jsx
to manage the questions & answers - output
<Header>
&<Quiz>
components inApp.jsx
- create a
questions.js
file with questions & answers inside - change the logic in
Quiz.jsx
for managing questions & answers
- shuffle the answers by using the
sort
method inQuiz.jsx
- make sure the app doesn't break if we answer all the questions & display a summary instead of the quiz
- create a
QuestionTimer.jsx
component - set a progress bar inside
QuestionTimer.jsx
- define a timeout & an interval using the
useState
&useEffect
hooks insideQuestionTimer.jsx
- ouptut the
<QuestionTimer>
component insideQuiz.jsx
- make sure the timeout doesn't execute again by wrapping the
handleSelectAnswer
function with theuseCallback
hook inQuiz.jsx
- cleanup the existing interval if the effect function runs again in
QuestionTimer.jsx
- cleanup the existing timer to prevent it from keeping on going in
QuestionTimer.jsx
- reset the
<QuestionTimer>
component when the question changes by adding akey
prop to it
- add a new
answerState
state that controls our current answer state inQuiz.jsx
- dynamically change the color of the selected answer
- shuffle the answers once when the
activeQuestionIndex
changes by using theuseRef
hook inQuiz.jsx
- create a
Answers.jsx
component to make sure that the answers are shuffled every next questions & that the answer doesn't remain selected - output the
<Answers>
component inQuiz.jsx
- create a
Question.jsx
component to use only onekey
prop
- move the state down from the
Quiz.jsx
component to theQuestion.jsx
component - disable the button to prevent from clicking it when an answer was selected in
Answers.jsx
- update the
<QuestionTimer>
component inQuestion.jsx
- if an answer was selected so that a new timer starts and only expires after we showed the correct or wrong answer
- when this timer expires don't tell the
Quiz.jsx
component that the question was not answered
- add a
mode
prop inQuestionTimer.jsx
& set it as aclassName
, then set its value to theanswerState
inQuestion.jsx
for styling purposes - reset the interval whenever the timer changes to make the interval inline with the new timer and the new
max
value of theprogress
bar by adding akey
prop with a value oftimer
inQuestion.jsx
- trigger the
onSkipAnswer
function only if no answer was selected inQuestion.jsx
to avoid skipping questions unexpectedly
- create a
Summary.jsx
component - output the
<Summary>
component inQuiz.jsx
- use the
userAnswers
's object to derive all the different data points we need inSummary.jsx
- use the
index
as akey
to avoid encountering two children with the same key