Skip to content

Commit 2aa4950

Browse files
fix(useQuizWidget): revert seeping logic changes
1 parent 089a85c commit 2aa4950

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/components/Quiz/QuizWidget/useQuizWidget.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
RawQuiz,
1212
} from "../../../types"
1313
import questionBank from "../../../data/quizzes/questionBank"
14-
import { PASSING_QUIZ_SCORE } from "../../../constants"
14+
import { PASSING_QUIZ_SCORE, USER_STATS_KEY } from "../../../constants"
1515
import { trackCustomEvent } from "../../../utils/matomo"
1616
import { INITIAL_USER_STATS } from "../../../pages/quizzes"
1717

@@ -38,15 +38,15 @@ export const useQuizWidget = ({
3838
useState<AnswerChoice | null>(null)
3939
const [selectedAnswer, setSelectedAnswer] = useState<string | null>(null)
4040

41-
const { setUserStats, userStats } = useContext(QuizzesHubContext)
41+
const { setUserStats } = useContext(QuizzesHubContext)
4242

4343
useEffect(() => {
4444
// If quiz is standalone (out of Quiz Hub page),
4545
// stats required to be initialized on localStorage first
46-
const item = userStats
46+
const item = window.localStorage.getItem(USER_STATS_KEY)
4747

4848
if (item === null) {
49-
setUserStats(INITIAL_USER_STATS)
49+
localStorage.setItem(USER_STATS_KEY, JSON.stringify(INITIAL_USER_STATS))
5050
}
5151

5252
setNextQuiz(getNextQuiz(quizKey))

0 commit comments

Comments
 (0)