chore: more signals methods
This commit is contained in:
1 parent
4f9d67fb45
commit
c0315e55f4
3 files changed
+48
-23
No files matched your search
+1
-12
@@ -14,28 +14,17 @@ fn app(cx: Scope) -> Element {
|
||||
use_init_signal_rt(cx);
|
||||
|
||||
let mut count = use_signal(cx, || 0);
|
||||
let mut running = use_signal(cx, || false);
|
||||
|
||||
use_coroutine(cx, |_: UnboundedReceiver<()>| async move {
|
||||
loop {
|
||||
if running.get() {
|
||||
count += 1;
|
||||
}
|
||||
count += 1;
|
||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||
}
|
||||
});
|
||||
|
||||
cx.render(rsx! {
|
||||
h1 { "High-Five counter: {count}" }
|
||||
|
||||
button { onclick: move |_| count += 1, "Up high!" }
|
||||
button { onclick: move |_| count -= 1, "Down low!" }
|
||||
|
||||
button { onclick: move |_| running.set(!running.get()), "Start counting" }
|
||||
|
||||
|
||||
if count.get() > 3 {
|
||||
rsx! ( h2 { "Nice!" } )
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user