Move auth and timezone hooks into dedicated hook files
This commit is contained in:
@@ -9,19 +9,19 @@
|
||||
* always receive a safe fallback.
|
||||
*/
|
||||
|
||||
import { createContext, useContext, useMemo } from "react";
|
||||
import { createContext, useMemo } from "react";
|
||||
import { useTimezoneData } from "../hooks/useTimezoneData";
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Context definition
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
interface TimezoneContextValue {
|
||||
export interface TimezoneContextValue {
|
||||
/** IANA timezone string, e.g. ``"Europe/Berlin"`` or ``"UTC"``. */
|
||||
timezone: string;
|
||||
}
|
||||
|
||||
const TimezoneContext = createContext<TimezoneContextValue>({ timezone: "UTC" });
|
||||
export const TimezoneContext = createContext<TimezoneContextValue | undefined>(undefined);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Provider
|
||||
@@ -53,24 +53,3 @@ export function TimezoneProvider({
|
||||
<TimezoneContext.Provider value={value}>{children}</TimezoneContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Hook
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Return the IANA timezone string configured during setup.
|
||||
*
|
||||
* Must be used inside a {@link TimezoneProvider}.
|
||||
*
|
||||
* @returns The configured timezone, e.g. ``"Europe/Berlin"``.
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* const { timezone } = useTimezone();
|
||||
* const label = formatDate(item.created_at, timezone);
|
||||
* ```
|
||||
*/
|
||||
export function useTimezone(): string {
|
||||
return useContext(TimezoneContext).timezone;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user