readme.rs 709 B

12345678910111213141516171819202122
  1. //! The example from the readme!
  2. //!
  3. //! This example demonstrates how to create a simple counter app with dioxus. The `Signal` type wraps inner values,
  4. //! making them `Copy`, allowing them to be freely used in closures and async functions. `Signal` also provides
  5. //! helper methods like AddAssign, SubAssign, toggle, etc, to make it easy to update the value without running
  6. //! into lock issues.
  7. use dioxus::prelude::*;
  8. fn main() {
  9. dioxus::launch(app);
  10. }
  11. fn app() -> Element {
  12. let mut count = use_signal(|| 0);
  13. rsx! {
  14. h1 { "High-Five counter: {count}" }
  15. button { onclick: move |_| count += 1, "Up high!" }
  16. button { onclick: move |_| count -= 1, "Down low!" }
  17. }
  18. }