clock.rs 639 B

1234567891011121314151617181920212223242526272829303132
  1. //! Example: README.md showcase
  2. //!
  3. //! The example from the README.md.
  4. use dioxus::prelude::*;
  5. fn main() {
  6. dioxus_desktop::launch(app);
  7. }
  8. fn app(cx: Scope) -> Element {
  9. let count = use_ref(cx, || 0);
  10. let ct = count.to_owned();
  11. use_coroutine(cx, |_: UnboundedReceiver<()>| async move {
  12. loop {
  13. tokio::time::sleep(std::time::Duration::from_millis(10)).await;
  14. *ct.write() += 1;
  15. let current = *ct.read();
  16. println!("current: {}", current);
  17. }
  18. });
  19. let count = count.read();
  20. cx.render(rsx! {
  21. div { "High-Five counter: {count}" }
  22. })
  23. }