File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed
src/components/Quiz/QuizWidget Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import {
11
11
RawQuiz ,
12
12
} from "../../../types"
13
13
import questionBank from "../../../data/quizzes/questionBank"
14
- import { PASSING_QUIZ_SCORE } from "../../../constants"
14
+ import { PASSING_QUIZ_SCORE , USER_STATS_KEY } from "../../../constants"
15
15
import { trackCustomEvent } from "../../../utils/matomo"
16
16
import { INITIAL_USER_STATS } from "../../../pages/quizzes"
17
17
@@ -38,15 +38,15 @@ export const useQuizWidget = ({
38
38
useState < AnswerChoice | null > ( null )
39
39
const [ selectedAnswer , setSelectedAnswer ] = useState < string | null > ( null )
40
40
41
- const { setUserStats, userStats } = useContext ( QuizzesHubContext )
41
+ const { setUserStats } = useContext ( QuizzesHubContext )
42
42
43
43
useEffect ( ( ) => {
44
44
// If quiz is standalone (out of Quiz Hub page),
45
45
// stats required to be initialized on localStorage first
46
- const item = userStats
46
+ const item = window . localStorage . getItem ( USER_STATS_KEY )
47
47
48
48
if ( item === null ) {
49
- setUserStats ( INITIAL_USER_STATS )
49
+ localStorage . setItem ( USER_STATS_KEY , JSON . stringify ( INITIAL_USER_STATS ) )
50
50
}
51
51
52
52
setNextQuiz ( getNextQuiz ( quizKey ) )
You can’t perform that action at this time.
0 commit comments