Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: TriviaQuiz component persisting on gameOver #5

Open
crooks-s opened this issue Apr 2, 2024 · 0 comments
Open

Bug: TriviaQuiz component persisting on gameOver #5

crooks-s opened this issue Apr 2, 2024 · 0 comments

Comments

@crooks-s
Copy link
Contributor

crooks-s commented Apr 2, 2024

Bug Description

When the trivia game ends, <GameOver /> is rendered, but <TriviaQuiz /> still persists.

How to Reproduce

  • Download React Dev Tools - Google Chrome extension or another extension that allows you to view the components currently rendered in a React app.
  • In Chrome Dev Tools, navigate to the Components tab.
  • Start and complete the trivia game, but do not click "Play Again?"
  • On this page, observe the currently rendered components which should be App, GameOver, and TriviaQuiz, pictured below.

Screenshot 2024-04-02 at 2 05 22 PM

Expected Behavior

Only <GameOver /> should render in the application's current state as there is no need for <TriviaQuiz /> once the game ends.

Solution

In the App component, we can fix the ternary JSX expression using the following code block:

{!gameOver ? (
  !startTrivia ? (
    <TriviaSetup
      topic={topic}
      setTopic={setTopic}
      questionCount={questionCount}
      setQuestionCount={setQuestionCount}
      generateQuiz={generateQuiz}
    />
  ) : (
    <TriviaQuiz
      currentQuestionIndex={currentQuestionIndex}
      setCurrentQuestionIndex={setCurrentQuestionIndex}
      questions={questions}
      setGameOver={setGameOver}
    />
  )
) : (
  <GameOver />
)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant