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