Skip to content

Commit

Permalink
quiz play loop call fix (reactplay#560)
Browse files Browse the repository at this point in the history
* quiz play loop call fix

* react-router version change
  • Loading branch information
Angryman18 authored Sep 19, 2022
1 parent 1b2783f commit 268558d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"react-organizational-chart": "^2.1.1",
"react-qr-code": "^2.0.7",
"react-redux": "^8.0.1",
"react-router-dom": "^6.3.0",
"react-router-dom": "6.3.0",
"react-scripts": "5.0.0",
"react-shimmer-effect": "^1.0.9",
"react-simple-maps": "^2.3.0",
Expand Down
10 changes: 6 additions & 4 deletions src/plays/fun-quiz/QuizScreen.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState, useCallback } from "react";
import { useEffect, useState, useCallback, useRef } from "react";

import "./QuizScreen.scss";

Expand All @@ -25,10 +25,12 @@ function QuizScreen({ category, getQuizSummary }) {
const formatCategoryText = category === "all" ? "" : `&category=${category}`;
const currentQuestion = quizData?.data?.[questionNumber];

const nonPremitiveReference = useRef(quizData)

useEffect(() => {
(async () => {
try {
setQuizData({ ...quizData, loading: true });
setQuizData({ ...nonPremitiveReference.current, loading: true });
const response = await fetch(
`https://opentdb.com/api.php?amount=20${formatCategoryText}&type=multiple`
);
Expand All @@ -51,10 +53,10 @@ function QuizScreen({ category, getQuizSummary }) {
error: false,
});
} catch (err) {
setQuizData({ ...quizData, loading: false, error: true });
setQuizData({ ...nonPremitiveReference.current, loading: false, error: true });
}
})();
}, [formatCategoryText, quizData]);
}, [formatCategoryText, nonPremitiveReference]);

// select and deselect the answer
const handleAnswerClick = (val) => (e) => {
Expand Down

0 comments on commit 268558d

Please sign in to comment.