ach ich weiß nicht

This commit is contained in:
philipredstone
2025-04-17 13:06:50 +02:00
parent 56c0867a20
commit e60ec9248d
61 changed files with 2538 additions and 2323 deletions

View File

@ -0,0 +1,30 @@
import { useState, useEffect, useCallback, RefObject } from 'react';
import { ToastItem } from '../types/types';
export const useToastNotifications = () => {
const [toasts, setToasts] = useState<ToastItem[]>([]);
const addToast = useCallback(
(message: string, type: 'error' | 'success' | 'warning' | 'info' = 'success') => {
const id = Date.now();
const newToast = {
id,
message,
type,
onClose: () => removeToast(id),
};
setToasts(prevToasts => [...prevToasts, newToast]);
// Auto-remove after 3 seconds
setTimeout(() => removeToast(id), 3000);
},
[]
);
const removeToast = useCallback((id: number) => {
setToasts(prevToasts => prevToasts.filter(toast => toast.id !== id));
}, []);
return { toasts, addToast, removeToast };
};