diff --git a/src/state.rs b/src/state.rs index 669ecca..ab67050 100644 --- a/src/state.rs +++ b/src/state.rs @@ -19,6 +19,8 @@ pub struct Inner<'a, T> { updated: bool, } +pub struct Mount; + pub fn use_state(v: T) -> State { State { value: Arc::new(Mutex::new(v)), @@ -112,6 +114,12 @@ impl HookDependency for State { } } +impl HookDependency for Mount { + fn on_update(&self, hook: HookEffect) { + hook.call(); + } +} + pub fn use_effect(f: F, dependencies: &[&dyn HookDependency]) { let f = Arc::new(Mutex::new(f)); let hook = HookEffect(Arc::new(Mutex::new({ @@ -126,3 +134,7 @@ pub fn use_effect(f: F, dependencies: &[&dyn d.on_update(hook.clone()); } } + +pub fn use_mount() -> Mount { + Mount +}