dioxus/packages/signals/examples/dependancies.rs

30 lines
633 B
Rust
Raw Normal View History

use dioxus::prelude::*;
fn main() {
2024-01-31 01:59:57 +00:00
launch(app);
}
fn app() -> Element {
let mut signal = use_signal(|| 0);
use_future(move || async move {
loop {
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
signal += 1;
}
});
let mut local_state = use_signal(|| 0);
2024-01-21 07:32:12 +00:00
let computed = use_memo_with_dependencies((&local_state(),), move |(local_state,)| {
local_state * 2 + signal.cloned()
});
println!("Running app");
2024-01-16 19:18:46 +00:00
rsx! {
button { onclick: move |_| local_state.set(local_state() + 1), "Add one" }
div { "{computed}" }
}
}