diff --git a/client/src/templates/Challenges/quiz/show.tsx b/client/src/templates/Challenges/quiz/show.tsx index 7f9982b7234..b22705d573c 100644 --- a/client/src/templates/Challenges/quiz/show.tsx +++ b/client/src/templates/Challenges/quiz/show.tsx @@ -1,4 +1,4 @@ -import { graphql, navigate } from 'gatsby'; +import { graphql } from 'gatsby'; import React, { useCallback, useEffect, useRef, useState } from 'react'; import Helmet from 'react-helmet'; import { ObserveKeys } from 'react-hotkeys'; @@ -128,7 +128,7 @@ const ShowQuiz = ({ const [showUnanswered, setShowUnanswered] = useState(false); - const [exitConfirmed, setExitConfirmed] = useState(false); + const exitConfirmed = useRef(false); const [exitPathname, setExitPathname] = useState(blockHashSlug); @@ -247,8 +247,8 @@ const ShowQuiz = ({ }; const handleExitQuizModalBtnClick = () => { - setExitConfirmed(true); - void navigate(exitPathname || '/learn'); + exitConfirmed.current = true; + void reachNavigate(exitPathname || '/learn'); closeExitQuizModal(); }; @@ -267,7 +267,7 @@ const ShowQuiz = ({ // - If they don't pass, the Finish Quiz button is disabled, there isn't anything for them to do other than leaving the page // - If they pass, the Submit-and-go button shows up, and campers should be allowed to leave the page // - When they have clicked the exit button on the exit modal - if (hasSubmitted || exitConfirmed) { + if (hasSubmitted || exitConfirmed.current) { return; } @@ -283,13 +283,7 @@ const ShowQuiz = ({ void reachNavigate(`${curLocation.pathname}`); openExitQuizModal(); }, - [ - curLocation.pathname, - hasSubmitted, - exitConfirmed, - openExitQuizModal, - blockHashSlug - ] + [curLocation.pathname, hasSubmitted, openExitQuizModal, blockHashSlug] ); usePageLeave({