feat: re-unify set_state

This commit is contained in:
Jonathan Kelley committed 2022-03-04 14:29:45 -05:00
1 parent 3928856a9b
commit 6c3f5195f4
16 files changed
+199 -136

No files matched your search

+4 -4
View File
@@ -10,14 +10,14 @@ fn main() {
}
fn app(cx: Scope) -> Element {
let (count, set_count) = use_state(&cx, || 0);
let count = use_state(&cx, || 0);
use_future(&cx, (), move |_| {
let set_count = set_count.clone();
let count = count.clone();
async move {
loop {
tokio::time::sleep(Duration::from_millis(1000)).await;
set_count.modify(|f| f + 1);
count.modify(|f| f + 1);
}
}
});
@@ -26,7 +26,7 @@ fn app(cx: Scope) -> Element {
div {
h1 { "Current count: {count}" }
button {
onclick: move |_| set_count(0),
onclick: move |_| count.set(0),
"Reset the count"
}
}