|
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 |
|
}; |
|
}; |