From ae993e0823f222ed5c89eddd40a6adbabd191a02 Mon Sep 17 00:00:00 2001 From: YuHyun Date: Fri, 29 Dec 2023 15:44:41 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20QuizCoachProvider=20=EC=BB=B4=ED=8F=AC?= =?UTF-8?q?=EB=84=8C=ED=8A=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [#304] --- .../QuizCoachContext/QuizCoachProvider.tsx | 32 +++++++++++++++++++ .../src/contexts/QuizCoachContext/index.ts | 5 +++ .../QuizCoachContext/quizCoachContext.ts | 19 +++++++++++ 3 files changed, 56 insertions(+) create mode 100644 packages/frontend/src/contexts/QuizCoachContext/QuizCoachProvider.tsx create mode 100644 packages/frontend/src/contexts/QuizCoachContext/index.ts create mode 100644 packages/frontend/src/contexts/QuizCoachContext/quizCoachContext.ts diff --git a/packages/frontend/src/contexts/QuizCoachContext/QuizCoachProvider.tsx b/packages/frontend/src/contexts/QuizCoachContext/QuizCoachProvider.tsx new file mode 100644 index 00000000..4fe867a5 --- /dev/null +++ b/packages/frontend/src/contexts/QuizCoachContext/QuizCoachProvider.tsx @@ -0,0 +1,32 @@ +import { ReactNode, useCallback, useMemo, useState } from "react"; + +import { QuizCoachActionContext, QuizCoachContext } from "./quizCoachContext"; + +interface QuizCoachProviderProps { + children: ReactNode; +} + +export function QuizCoachProvider({ children }: QuizCoachProviderProps) { + const [run, setRun] = useState(false); + + const handleEnd = useCallback(() => { + setRun(false); + }, []); + + const handleStart = useCallback(() => { + setRun(true); + }, []); + + const quizCoachActionContextValue = useMemo( + () => ({ handleEnd, handleStart }), + [handleEnd, handleStart], + ); + + return ( + + + {children} + + + ); +} diff --git a/packages/frontend/src/contexts/QuizCoachContext/index.ts b/packages/frontend/src/contexts/QuizCoachContext/index.ts new file mode 100644 index 00000000..57851705 --- /dev/null +++ b/packages/frontend/src/contexts/QuizCoachContext/index.ts @@ -0,0 +1,5 @@ +export { + useQuizCoachContext, + useQuizCoachActionContext, +} from "./quizCoachContext"; +export { QuizCoachProvider } from "./QuizCoachProvider"; diff --git a/packages/frontend/src/contexts/QuizCoachContext/quizCoachContext.ts b/packages/frontend/src/contexts/QuizCoachContext/quizCoachContext.ts new file mode 100644 index 00000000..ddc163c6 --- /dev/null +++ b/packages/frontend/src/contexts/QuizCoachContext/quizCoachContext.ts @@ -0,0 +1,19 @@ +import { createContext, useContext } from "react"; + +type QuizCoachActionContextType = { + handleEnd: () => void; + handleStart: () => void; +}; + +export const QuizCoachContext = createContext(false); +export const QuizCoachActionContext = createContext( + {} as QuizCoachActionContextType, +); + +export function useQuizCoachContext() { + return useContext(QuizCoachContext); +} + +export function useQuizCoachActionContext() { + return useContext(QuizCoachActionContext); +}