create global selectors

This commit is contained in:
Evan Almloff committed 2024-01-19 15:26:28 -06:00
1 parent e4c84f91e1
commit c859ed3b12
4 files changed
+197 -19

No files matched your search

+2 -1
View File
@@ -5,6 +5,7 @@
use dioxus::prelude::*;
static COUNT: GlobalSignal<i32> = Signal::global(|| 0);
static DOUBLED_COUNT: GlobalSelector<i32> = Signal::global_selector(|| COUNT() * 2);
fn main() {
launch_desktop(app);
@@ -12,7 +13,7 @@ fn main() {
fn app() -> Element {
rsx! {
h1 { "High-Five counter: {COUNT}" }
h1 { "{COUNT} x 2 = {DOUBLED_COUNT}" }
button { onclick: move |_| *COUNT.write() += 1, "Up high!" }
button { onclick: move |_| *COUNT.write() -= 1, "Down low!" }
}