Skip to content

Commit

Permalink
Merge pull request #177 from tahmid-saj/dev-ts-user-context
Browse files Browse the repository at this point in the history
migrating user context to ts
  • Loading branch information
tahmid-saj authored Oct 4, 2024
2 parents 118f11b + 583519f commit 63102f8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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<UserContextType>({
currentUser: undefined,
});

export const UserProvider = ({ children }) => {
const [currentUser, setCurrentUser] = useState(null);
export const UserProvider: FC<UserProviderProps> = ({ children }) => {
const [currentUser, setCurrentUser] = useState<any | undefined>(undefined);
const value = { currentUser, setCurrentUser };

// signOutUser();
Expand Down
11 changes: 11 additions & 0 deletions src/contexts/shared/user/user.types.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ReactNode } from "react";

// user types

export interface UserContextType {
currentUser: any | undefined;
}

export interface UserProviderProps {
children: ReactNode;
}

0 comments on commit 63102f8

Please sign in to comment.