readme.rs 585 B

1234567891011121314151617181920212223242526272829
  1. use dioxus::prelude::*;
  2. fn main() {
  3. launch(app);
  4. }
  5. fn app() -> Element {
  6. let mut count = use_signal(|| 0);
  7. use_effect(move || {
  8. println!("The count is now: {}", count);
  9. });
  10. rsx! {
  11. h1 { "High-Five counter: {count}" }
  12. Child { sig: count }
  13. button { onclick: move |_| count += 1, "Up high!" }
  14. button { onclick: move |_| count -= 1, "Down low!" }
  15. }
  16. }
  17. #[component]
  18. fn Child(sig: Signal<i32>) -> Element {
  19. let doubled = use_memo(move || sig() * 2);
  20. rsx! {
  21. "The count is: {sig}, doubled: {doubled}"
  22. }
  23. }