1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use yew::{hook, use_context};

use crate::manager::NotificationsManager;
use crate::Notifiable;

/// This hook is used to manage notifications.
/// Returned [`NotificationsManager`] can be used to spawn new notifications of the type `T`.
///
/// # Example
///
/// ```rust
/// use yew_notifications::{Notification, use_notification};
///
/// let notifications_manager = use_notification::<Notification>();
/// notifications_manager.spawn(Notification::new(/* */));
/// ```
#[hook]
pub fn use_notification<T: Notifiable + PartialEq + Clone>() -> NotificationsManager<T> {
    use_context::<NotificationsManager<T>>().unwrap_or_default()
}