Skip to content

Commit

Permalink
feat: QuizCoachProvider 컴포넌트 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
YuHyun-P committed Feb 3, 2024
1 parent 46d3233 commit 92a09a3
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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 (
<QuizCoachContext.Provider value={run}>
<QuizCoachActionContext.Provider value={quizCoachActionContextValue}>
{children}
</QuizCoachActionContext.Provider>
</QuizCoachContext.Provider>
);
}
5 changes: 5 additions & 0 deletions packages/frontend/src/contexts/QuizCoachContext/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export {
useQuizCoachContext,
useQuizCoachActionContext,
} from "./quizCoachContext";
export { QuizCoachProvider } from "./QuizCoachProvider";
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { createContext, useContext } from "react";

type QuizCoachActionContextType = {
handleEnd: () => void;
handleStart: () => void;
};

export const QuizCoachContext = createContext(false);
export const QuizCoachActionContext = createContext<QuizCoachActionContextType>(
{} as QuizCoachActionContextType,
);

export function useQuizCoachContext() {
return useContext(QuizCoachContext);
}

export function useQuizCoachActionContext() {
return useContext(QuizCoachActionContext);
}

0 comments on commit 92a09a3

Please sign in to comment.