Skip to content

Commit

Permalink
feat: 퀴즈 튜토리얼 완료 여부 값 로컬 스토리지로 관리
Browse files Browse the repository at this point in the history
  • Loading branch information
YuHyun-P committed Feb 3, 2024
1 parent 05b4bab commit a32f5cf
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { ReactNode, useCallback, useMemo, useState } from "react";
import { ReactNode, useCallback, useEffect, useMemo, useState } from "react";

import { createLocalStorage } from "../../utils/webStorage";

import { QuizCoachActionContext, QuizCoachContext } from "./quizCoachContext";

const quizTutorialEndStorage = createLocalStorage("quiz-tutorial-end", false);

interface QuizCoachProviderProps {
children: ReactNode;
}
Expand All @@ -11,17 +15,24 @@ export function QuizCoachProvider({ children }: QuizCoachProviderProps) {

const handleEnd = useCallback(() => {
setRun(false);
quizTutorialEndStorage.setItem(true);
}, []);

const handleStart = useCallback(() => {
setRun(true);
quizTutorialEndStorage.removeItem();
}, []);

const quizCoachActionContextValue = useMemo(
() => ({ handleEnd, handleStart }),
[handleEnd, handleStart],
);

useEffect(() => {
const tutorialEnd = quizTutorialEndStorage.getItem();
setRun(!tutorialEnd);
}, []);

return (
<QuizCoachContext.Provider value={run}>
<QuizCoachActionContext.Provider value={quizCoachActionContextValue}>
Expand Down

0 comments on commit a32f5cf

Please sign in to comment.