added greeting with context logic

This commit is contained in:
2025-10-25 15:59:52 +02:00
parent 770025f8fc
commit a0bdf5539c
5 changed files with 45 additions and 15 deletions

View 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;
}