2025-09-16 11:07:35 +01:00
|
|
|
import { createContext, useContext } from "react";
|
2025-09-16 14:20:38 +01:00
|
|
|
import type { AlertState, AlertPayload } from "../types/types";
|
2025-09-16 11:07:35 +01:00
|
|
|
|
|
|
|
|
type AlertHitContextValueType = {
|
|
|
|
|
state: AlertState;
|
2025-09-16 14:20:38 +01:00
|
|
|
action?: AlertPayload;
|
|
|
|
|
dispatch: React.Dispatch<AlertPayload>;
|
2025-09-24 12:28:14 +01:00
|
|
|
isLoading?: boolean;
|
|
|
|
|
isError?: boolean;
|
|
|
|
|
error?: Error | null;
|
2025-09-16 11:07:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const AlertHitContext = createContext<
|
|
|
|
|
AlertHitContextValueType | undefined
|
|
|
|
|
>(undefined);
|
|
|
|
|
|
|
|
|
|
export const useAlertHitContext = () => {
|
|
|
|
|
const ctx = useContext(AlertHitContext);
|
|
|
|
|
if (!ctx)
|
|
|
|
|
throw new Error("useAlertHitContext must be used within <AlertHitContext>");
|
|
|
|
|
return ctx;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default AlertHitContext;
|