init
This commit is contained in:
34
hooks/use-user-context.tsx
Normal file
34
hooks/use-user-context.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
"use client";
|
||||
|
||||
import { createContext, useContext, useState, ReactNode } from "react";
|
||||
|
||||
interface UserInfo {
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
teamName: string;
|
||||
}
|
||||
|
||||
interface UserContextType {
|
||||
userInfo: UserInfo | null;
|
||||
setUserInfo: (userInfo: UserInfo | null) => void;
|
||||
}
|
||||
|
||||
const UserContext = createContext<UserContextType | undefined>(undefined);
|
||||
|
||||
export function UserProvider({ children }: { children: ReactNode }) {
|
||||
const [userInfo, setUserInfo] = useState<UserInfo | null>(null);
|
||||
|
||||
return (
|
||||
<UserContext.Provider value={{ userInfo, setUserInfo }}>
|
||||
{children}
|
||||
</UserContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useUser() {
|
||||
const context = useContext(UserContext);
|
||||
if (context === undefined) {
|
||||
throw new Error("useUser must be used within a UserProvider");
|
||||
}
|
||||
return context;
|
||||
}
|
||||
Reference in New Issue
Block a user