22 lines
587 B
TypeScript
22 lines
587 B
TypeScript
|
|
import { createContext, useContext } from "react";
|
||
|
|
import type { AlertState, AlertPayload, ActionType } from "../types/types";
|
||
|
|
|
||
|
|
type AlertHitContextValueType = {
|
||
|
|
state: AlertState;
|
||
|
|
action: AlertPayload;
|
||
|
|
disptach: (action: ActionType) => AlertState;
|
||
|
|
};
|
||
|
|
|
||
|
|
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;
|