State syncing

This commit is contained in:
2026-01-26 17:27:47 +01:00
parent 86e3f4e684
commit 506ccae049
2 changed files with 26 additions and 29 deletions
+22
View File
@@ -189,3 +189,25 @@ pub fn use_sync_state<
state
}
pub fn use_sync_effect<
T: Send + Sync + 'static,
Ev: 'static,
E: Fn(&State<T>) -> Ev + Send + Sync + 'static,
>(
cx: &Arc<Context>,
state: &State<T>,
encoder: E,
deps: &[&dyn HookDependency],
) {
use_effect(
{
let state = state.clone();
let cx = cx.clone();
move || {
cx.emit_event(&encoder(&state));
}
},
deps,
);
}