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
use super::use_effect_once;

/// A lifecycle hook that calls a function after the component is mounted.
///
/// # Example
/// ```rust
/// # use yew::prelude::*;
/// # use log::debug;
/// #
/// # use yew_hooks::use_mount;
/// #
/// #[function_component(Mount)]
/// fn mount() -> Html {
///     use_mount(|| {
///         debug!("Running effect once on mount");
///     });
///     
///     html! {
///         <>
///         </>
///     }
///
/// }
/// ```
pub fn use_mount<Callback>(callback: Callback)
where
    Callback: FnOnce() + 'static,
{
    use_effect_once(move || {
        callback();

        || ()
    });
}