Multimodel_Rag / frontend /src /hooks /useToast.ts
Dhrumil Parikh
deploy GeminiRAG
cdc55f4
Raw
History Blame Contribute Delete
691 Bytes
import { useState, useCallback } from "react";
export type ToastType = "success" | "error" | "info";
export interface Toast {
id: number;
message: string;
type: ToastType;
}
let _id = 0;
export function useToast() {
const [toasts, setToasts] = useState<Toast[]>([]);
const addToast = useCallback((message: string, type: ToastType = "info") => {
const id = ++_id;
setToasts(prev => [...prev, { id, message, type }]);
setTimeout(() => setToasts(prev => prev.filter(t => t.id !== id)), 4000);
}, []);
const removeToast = useCallback((id: number) => {
setToasts(prev => prev.filter(t => t.id !== id));
}, []);
return { toasts, addToast, removeToast };
}