diff --git a/examples/clock.rs b/examples/clock.rs index 2ed4812cf..f9c1892d9 100644 --- a/examples/clock.rs +++ b/examples/clock.rs @@ -1,65 +1,22 @@ -#![allow(non_snake_case)] - use dioxus::prelude::*; -use dioxus_signals::{use_signal, Effect, Signal}; +use dioxus_signals::use_signal; fn main() { dioxus_desktop::launch(app); } fn app(cx: Scope) -> Element { - println!("running app"); - - let counts = use_signal(cx, || (0..100).map(Signal::new).collect::>()); - - cx.use_hook(|| { - Effect::new(move || { - println!("Counts: {:?}", counts); - }) - }); - - render! { - for (i, count) in counts.into_iter().enumerate() { - Child { - id: i, - count: count, - } - } - } -} - -#[derive(Props, PartialEq)] -struct ChildProps { - id: usize, - count: Signal, -} - -fn Child(cx: Scope) -> Element { - println!("running child {}", cx.props.id); - let count = cx.props.count; + let mut count = use_signal(cx, || 0); use_future!(cx, || async move { loop { - tokio::time::sleep(std::time::Duration::from_secs(count.value())).await; - *count.write() += 1; + tokio::time::sleep(std::time::Duration::from_millis(100)).await; + count += 1; + println!("current: {count}"); } }); - render! { - div { - "Child: {count}" - button { - onclick: move |_| { - *count.write() += 1; - }, - "Increase" - } - button { - onclick: move |_| { - *count.write() -= 1; - }, - "Decrease" - } - } - } + cx.render(rsx! { + div { "High-Five counter: {count}" } + }) }