yew/functional/hooks/
mod.rs1mod use_callback;
2mod use_context;
3mod use_effect;
4mod use_force_update;
5mod use_memo;
6mod use_prepared_state;
7mod use_reducer;
8mod use_ref;
9mod use_state;
10
11mod use_transitive_state;
12
13pub use use_callback::*;
14pub use use_context::*;
15pub use use_effect::*;
16pub use use_force_update::*;
17pub use use_memo::*;
18pub use use_prepared_state::*;
19pub use use_reducer::*;
20pub use use_ref::*;
21pub use use_state::*;
22pub use use_transitive_state::*;
23
24use crate::functional::HookContext;
25
26#[must_use = "hooks do nothing unless called inside a `#[hook]` or `#[component]` function"]
32pub trait Hook {
33 type Output;
35
36 fn run(self, ctx: &mut HookContext) -> Self::Output;
38}
39
40#[doc(hidden)]
42#[allow(missing_debug_implementations, missing_docs)]
43pub struct BoxedHook<'hook, T> {
44 inner: Box<dyn 'hook + FnOnce(&mut HookContext) -> T>,
45}
46
47impl<'hook, T> BoxedHook<'hook, T> {
48 #[allow(missing_docs)]
49 pub fn new(inner: Box<dyn 'hook + FnOnce(&mut HookContext) -> T>) -> Self {
50 Self { inner }
51 }
52}
53
54impl<T> Hook for BoxedHook<'_, T> {
55 type Output = T;
56
57 fn run(self, ctx: &mut HookContext) -> Self::Output {
58 (self.inner)(ctx)
59 }
60}