dioxus/packages/signals/examples/selector.rs

30 lines
533 B
Rust
Raw Normal View History

2023-08-08 20:27:45 +00:00
use dioxus::prelude::*;
use dioxus_signals::*;
fn main() {
dioxus_desktop::launch(App);
2023-08-08 20:27:45 +00:00
}
#[component]
fn App(cx: Scope) -> Element {
2023-08-08 20:27:45 +00:00
let signal = use_signal(cx, || 0);
let doubled = use_selector(cx, move || signal * 2);
render! {
button {
onclick: move |_| *signal.write() += 1,
"Increase"
}
Child {
signal: doubled
}
}
}
#[component]
2023-08-08 20:27:45 +00:00
fn Child(cx: Scope, signal: ReadOnlySignal<usize>) -> Element {
render! {
"{signal}"
}
}