Add toggle to signals example
This commit is contained in:
parent
14b3fa72e4
commit
741bfbc9ac
|
@ -6,12 +6,15 @@ fn main() {
|
|||
}
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
let running = dioxus_signals::use_signal(cx, || true);
|
||||
let mut count = dioxus_signals::use_signal(cx, || 0);
|
||||
let saved_values = dioxus_signals::use_signal(cx, || vec![0]);
|
||||
|
||||
use_future!(cx, || async move {
|
||||
loop {
|
||||
count += 1;
|
||||
if running.value() {
|
||||
count += 1;
|
||||
}
|
||||
tokio::time::sleep(Duration::from_millis(400)).await;
|
||||
}
|
||||
});
|
||||
|
@ -20,10 +23,8 @@ fn app(cx: Scope) -> Element {
|
|||
h1 { "High-Five counter: {count}" }
|
||||
button { onclick: move |_| count += 1, "Up high!" }
|
||||
button { onclick: move |_| count -= 1, "Down low!" }
|
||||
button {
|
||||
onclick: move |_| saved_values.push(count.value()),
|
||||
"Save this value"
|
||||
}
|
||||
button { onclick: move |_| running.set(!running.value()), "Toggle counter" }
|
||||
button { onclick: move |_| saved_values.push(count.value()), "Save this value" }
|
||||
|
||||
// We can do boolean operations on the current signal value
|
||||
if count.value() > 5 {
|
||||
|
|
Loading…
Reference in New Issue