Move auth and timezone hooks into dedicated hook files
This commit is contained in:
15
frontend/src/hooks/useAuth.ts
Normal file
15
frontend/src/hooks/useAuth.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { useContext } from "react";
|
||||
import { AuthContext, type AuthContextValue } from "../providers/AuthProvider";
|
||||
|
||||
/**
|
||||
* Access authentication state and actions from a mounted AuthProvider.
|
||||
*
|
||||
* @throws {Error} When called outside of `<AuthProvider>`.
|
||||
*/
|
||||
export function useAuth(): AuthContextValue {
|
||||
const ctx = useContext(AuthContext);
|
||||
if (ctx === null) {
|
||||
throw new Error("useAuth must be used within <AuthProvider>.");
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
15
frontend/src/hooks/useTimezone.ts
Normal file
15
frontend/src/hooks/useTimezone.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { useContext } from "react";
|
||||
import { TimezoneContext } from "../providers/TimezoneProvider";
|
||||
|
||||
/**
|
||||
* Return the configured IANA timezone from the mounted TimezoneProvider.
|
||||
*
|
||||
* @throws {Error} When called outside of `<TimezoneProvider>`.
|
||||
*/
|
||||
export function useTimezone(): string {
|
||||
const context = useContext(TimezoneContext);
|
||||
if (context === undefined) {
|
||||
throw new Error("useTimezone must be used within <TimezoneProvider>.");
|
||||
}
|
||||
return context.timezone;
|
||||
}
|
||||
Reference in New Issue
Block a user