dioxus/packages/signals/examples/send.rs

27 lines
534 B
Rust
Raw Normal View History

2023-11-07 19:15:19 +00:00
use dioxus::prelude::*;
use dioxus_signals::*;
fn main() {
tracing_subscriber::fmt::init();
dioxus_desktop::launch(App);
}
#[component]
fn App(cx: Scope) -> Element {
let mut signal = use_signal_sync(cx, || 0);
cx.use_hook(|| {
std::thread::spawn(move || loop {
std::thread::sleep(std::time::Duration::from_secs(1));
signal += 1;
})
});
render! {
button {
onclick: move |_| signal += 1,
"Increase"
}
"{signal}"
}
}