dioxus/examples/global.rs

21 lines
491 B
Rust
Raw Normal View History

2024-01-19 19:46:17 +00:00
//! Example: README.md showcase
//!
//! The example from the README.md.
use dioxus::prelude::*;
fn main() {
2024-01-20 08:11:55 +00:00
launch(app);
2024-01-19 19:46:17 +00:00
}
2024-01-21 07:32:12 +00:00
static COUNT: GlobalSignal<i32> = Signal::global(|| 0);
static DOUBLED_COUNT: GlobalMemo<i32> = Signal::global_memo(|| COUNT() * 2);
2024-01-19 19:46:17 +00:00
fn app() -> Element {
rsx! {
2024-01-19 21:26:28 +00:00
h1 { "{COUNT} x 2 = {DOUBLED_COUNT}" }
2024-01-19 19:46:17 +00:00
button { onclick: move |_| *COUNT.write() += 1, "Up high!" }
button { onclick: move |_| *COUNT.write() -= 1, "Down low!" }
}
}