From eb270ef0625033bbd42e5f08745c027eae10c204 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Sat, 28 May 2022 12:52:49 -0500 Subject: [PATCH] update component on submitting --- examples/hot_reload.rs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/examples/hot_reload.rs b/examples/hot_reload.rs index e4e0a6f05..a3472829d 100644 --- a/examples/hot_reload.rs +++ b/examples/hot_reload.rs @@ -1,23 +1,13 @@ use dioxus::prelude::*; -use std::time::Duration; fn main() { - dioxus::desktop::launch_with_props(with_hot_reload, app, |b| b); + dioxus::web::launch_with_props(with_hot_reload, app, |c| c); } fn app(cx: Scope) -> Element { let count = use_state(&cx, || 170); let rsx_code = use_state(&cx, || None); - - use_future(&cx, (), move |_| { - let mut count = count.clone(); - async move { - loop { - tokio::time::sleep(Duration::from_millis(1000)).await; - count += 1; - } - } - }); + let re_render = cx.schedule_update(); cx.render(rsx! { div { @@ -54,6 +44,7 @@ fn app(cx: Scope) -> Element { if let Some(code) = rsx_code.get(){ let rsx_text_index: RsxTextIndex = cx.consume_context().unwrap(); rsx_text_index.insert(__line_num.clone(), code.clone()); + re_render(); } }, "submit" @@ -65,7 +56,7 @@ fn app(cx: Scope) -> Element { } div { - width: format!("{}px", count), + width: "{count}px", height: "10px", background_color: "red", } @@ -95,7 +86,7 @@ struct CompProps { fn Comp(cx: Scope) -> Element { cx.render(rsx! { h1 { - color: cx.props.color, + color: "{cx.props.color}", "Hello, from a component!" } })