mirror of
https://github.com/Crosstalk-Solutions/project-nomad.git
synced 2026-03-28 11:39:26 +01:00
29 lines
735 B
TypeScript
29 lines
735 B
TypeScript
import { createContext, useContext } from "react";
|
|
|
|
export interface Notification {
|
|
message: string;
|
|
type: "error" | "success" | "info";
|
|
duration?: number; // in milliseconds
|
|
}
|
|
|
|
export interface NotificationContextType {
|
|
notifications: Notification[];
|
|
addNotification: (notification: Notification) => void;
|
|
removeNotification: (id: string) => void;
|
|
removeAllNotifications: () => void;
|
|
}
|
|
|
|
export const NotificationContext = createContext<
|
|
NotificationContextType | undefined
|
|
>(undefined);
|
|
|
|
export const useNotifications = () => {
|
|
const context = useContext(NotificationContext);
|
|
if (!context) {
|
|
throw new Error(
|
|
"useNotifications must be used within a NotificationProvider"
|
|
);
|
|
}
|
|
return context;
|
|
};
|