From 583519fcec8b9e4f99a298a61c69f5d9d0d8f11b Mon Sep 17 00:00:00 2001 From: tahmid-saj Date: Fri, 4 Oct 2024 00:11:12 -0400 Subject: [PATCH] migrating user context to ts --- .../user/{user.context.jsx => user.context.tsx} | 13 +++++++------ src/contexts/shared/user/user.types.tsx | 11 +++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) rename src/contexts/shared/user/{user.context.jsx => user.context.tsx} (61%) create mode 100644 src/contexts/shared/user/user.types.tsx diff --git a/src/contexts/shared/user/user.context.jsx b/src/contexts/shared/user/user.context.tsx similarity index 61% rename from src/contexts/shared/user/user.context.jsx rename to src/contexts/shared/user/user.context.tsx index a600556..f583b19 100644 --- a/src/contexts/shared/user/user.context.jsx +++ b/src/contexts/shared/user/user.context.tsx @@ -1,17 +1,18 @@ -import { createContext, useEffect, useState } from "react"; +import { createContext, FC, useEffect, useState } from "react"; import { onAuthStateChangedListener, signOutUser, createUserDocumentFromAuth } from "../../../utils/firebase/firebase.utils"; +import { UserContextType, UserProviderProps } from "./user.types" + // actual value to be accessed -export const UserContext = createContext({ - currentUser: null, - setCurrentUser: () => null +export const UserContext = createContext({ + currentUser: undefined, }); -export const UserProvider = ({ children }) => { - const [currentUser, setCurrentUser] = useState(null); +export const UserProvider: FC = ({ children }) => { + const [currentUser, setCurrentUser] = useState(undefined); const value = { currentUser, setCurrentUser }; // signOutUser(); diff --git a/src/contexts/shared/user/user.types.tsx b/src/contexts/shared/user/user.types.tsx new file mode 100644 index 0000000..4c0fed9 --- /dev/null +++ b/src/contexts/shared/user/user.types.tsx @@ -0,0 +1,11 @@ +import { ReactNode } from "react"; + +// user types + +export interface UserContextType { + currentUser: any | undefined; +} + +export interface UserProviderProps { + children: ReactNode; +} \ No newline at end of file