File size: 1,045 Bytes
d5c104e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import { useState, useCallback } from 'react';
export const useNotification = () => {
const [notifications, setNotifications] = useState([]);
const addNotification = useCallback((notification) => {
const id = notification.id || `notification-${Date.now()}-${Math.random()}`;
const newNotification = {
id,
type: 'info',
dismissible: true,
autoDismiss: false,
duration: 5000,
showProgress: false,
...notification
};
setNotifications(prev => [...prev, newNotification]);
return id;
}, []);
const removeNotification = useCallback((id) => {
setNotifications(prev => prev.filter(n => n.id !== id));
}, []);
const clearAll = useCallback(() => {
setNotifications([]);
}, []);
const updateNotification = useCallback((id, updates) => {
setNotifications(prev =>
prev.map(n => n.id === id ? { ...n, ...updates } : n)
);
}, []);
return {
notifications,
addNotification,
removeNotification,
clearAll,
updateNotification
};
}; |