Dynamic scoping with if statement

This commit is contained in:
2026-01-25 02:17:08 +01:00
parent 05a390b10f
commit 6e481862ec
3 changed files with 72 additions and 24 deletions
+8 -1
View File
@@ -113,7 +113,14 @@ impl<T> HookDependency for State<T> {
}
pub fn use_effect<F: FnMut() + Send + Sync + 'static>(f: F, dependencies: &[&dyn HookDependency]) {
let hook = HookEffect(Arc::new(Mutex::new(f)));
let f = Arc::new(Mutex::new(f));
let hook = HookEffect(Arc::new(Mutex::new({
let f = f.clone();
move || {
let f = f.clone();
std::thread::spawn(move || (f.lock().unwrap())());
}
})));
for d in dependencies {
d.on_update(hook.clone());