Added use_mount

This commit is contained in:
2026-01-25 17:22:40 +01:00
parent b50ca3263b
commit 4afe1c24c2
+12
View File
@@ -19,6 +19,8 @@ pub struct Inner<'a, T> {
updated: bool, updated: bool,
} }
pub struct Mount;
pub fn use_state<T>(v: T) -> State<T> { pub fn use_state<T>(v: T) -> State<T> {
State { State {
value: Arc::new(Mutex::new(v)), value: Arc::new(Mutex::new(v)),
@@ -112,6 +114,12 @@ impl<T> HookDependency for State<T> {
} }
} }
impl HookDependency for Mount {
fn on_update(&self, hook: HookEffect) {
hook.call();
}
}
pub fn use_effect<F: FnMut() + Send + Sync + 'static>(f: F, dependencies: &[&dyn HookDependency]) { pub fn use_effect<F: FnMut() + Send + Sync + 'static>(f: F, dependencies: &[&dyn HookDependency]) {
let f = Arc::new(Mutex::new(f)); let f = Arc::new(Mutex::new(f));
let hook = HookEffect(Arc::new(Mutex::new({ let hook = HookEffect(Arc::new(Mutex::new({
@@ -126,3 +134,7 @@ pub fn use_effect<F: FnMut() + Send + Sync + 'static>(f: F, dependencies: &[&dyn
d.on_update(hook.clone()); d.on_update(hook.clone());
} }
} }
pub fn use_mount() -> Mount {
Mount
}