read_only_degrade.rs 664 B

123456789101112131415161718192021222324252627282930
  1. //! Signals can degrade into a ReadOnlySignal variant automatically
  2. //! This is done thanks to a conversion by the #[component] macro
  3. use dioxus::prelude::*;
  4. fn main() {
  5. dioxus::launch(app);
  6. }
  7. fn app() -> Element {
  8. let mut count = use_signal(|| 0);
  9. rsx! {
  10. h1 { "High-Five counter: {count}" }
  11. button { onclick: move |_| count += 1, "Up high!" }
  12. button { onclick: move |_| count -= 1, "Down low!" }
  13. Child {
  14. count,
  15. "hiiii"
  16. }
  17. }
  18. }
  19. #[component]
  20. fn Child(count: ReadOnlySignal<i32>, children: Element) -> Element {
  21. rsx! {
  22. div { "Count: {count}" }
  23. {children}
  24. }
  25. }