From 6520b24d6746522f1a7a060b2de2066b0c40341c Mon Sep 17 00:00:00 2001 From: Alejandro Osornio <50227494+AOx0@users.noreply.github.com> Date: Wed, 1 Jun 2022 15:52:43 -0500 Subject: [PATCH] Update index.md + Fix outdated documentation --- docs/guide/src/interactivity/index.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/guide/src/interactivity/index.md b/docs/guide/src/interactivity/index.md index 02c39b5b1..670ca5a40 100644 --- a/docs/guide/src/interactivity/index.md +++ b/docs/guide/src/interactivity/index.md @@ -64,7 +64,7 @@ The most common hook you'll use for storing state is `use_state`. `use_state` pr ```rust fn App(cx: Scope)-> Element { - let (post, set_post) = use_state(&cx, || { + let post = use_state(&cx, || { PostData { id: Uuid::new_v4(), score: 10, @@ -112,11 +112,11 @@ For example, let's say we provide a button to generate a new post. Whenever the ```rust fn App(cx: Scope)-> Element { - let (post, set_post) = use_state(&cx, || PostData::new()); + let post = use_state(&cx, || PostData::new()); cx.render(rsx!{ button { - onclick: move |_| set_post(PostData::random()) + onclick: move |_| post.set(PostData::random()) "Generate a random post" } Post { props: &post } @@ -141,19 +141,19 @@ We can use tasks in our components to build a tiny stopwatch that ticks every se ```rust fn App(cx: Scope)-> Element { - let (elapsed, set_elapsed) = use_state(&cx, || 0); - - use_future(&cx, || { - to_owned![set_elapsed]; // explicitly capture this hook for use in async + let elapsed = use_state(&cx, || 0); + + use_future(&cx, (), |()| { + to_owned![elapsed]; // explicitly capture this hook for use in async async move { loop { - TimeoutFuture::from_ms(1000).await; - set_elapsed.modify(|i| i + 1) + gloo_timers::future::TimeoutFuture::new(1_000).await; + elapsed.modify(|i| i + 1) } } }); - rsx!(cx, div { "Current stopwatch time: {sec_elapsed}" }) + rsx!(cx, div { "Current stopwatch time: {elapsed}" }) } ```