yew_notifications/hook.rs
1use yew::{hook, use_context};
2
3use crate::manager::NotificationsManager;
4use crate::Notifiable;
5
6/// This hook is used to manage notifications.
7/// Returned [`NotificationsManager`] can be used to spawn new notifications of the type `T`.
8///
9/// # Example
10///
11/// ```rust
12/// use yew_notifications::{Notification, use_notification};
13///
14/// let notifications_manager = use_notification::<Notification>();
15/// notifications_manager.spawn(Notification::new(/* */));
16/// ```
17#[hook]
18pub fn use_notification<T>() -> NotificationsManager<T>
19where
20 T: Notifiable + PartialEq + Clone,
21{
22 use_context::<NotificationsManager<T>>().unwrap_or_default()
23}