added greeting with context logic
This commit is contained in:
19
FrontendV2/src/states/Context.ts
Normal file
19
FrontendV2/src/states/Context.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { createContext } from "react";
|
||||
import { useContext } from "react";
|
||||
|
||||
export interface User {
|
||||
username: string;
|
||||
role: number;
|
||||
}
|
||||
|
||||
export const UserContext = createContext<User | undefined>(undefined);
|
||||
|
||||
export function useUserContext() {
|
||||
const user = useContext(UserContext);
|
||||
|
||||
if (user === undefined) {
|
||||
throw new Error("useUserContext must be used with a UserContext")
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
Reference in New Issue
Block a user