hot_reload.rs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. use dioxus::prelude::*;
  2. fn main() {
  3. dioxus::desktop::launch(app);
  4. }
  5. fn app(cx: Scope) -> Element {
  6. let count = use_state(&cx, || 170);
  7. cx.render(rsx! {
  8. div {
  9. width: "100%",
  10. height: "500px",
  11. onclick: move |_| {
  12. count.modify(|count| *count + 10);
  13. },
  14. p{"{__line_num:?}"}
  15. p {
  16. "High-Five counter: {count.to_string():?}",
  17. }
  18. div {
  19. width: "{count}px",
  20. height: "10px",
  21. background_color: "red",
  22. }
  23. Comp {
  24. color: "#083289"
  25. }
  26. Comp {
  27. color: "green"
  28. }
  29. {
  30. (0..10).map(|i| {
  31. cx.render(rsx!{p {"{i}"}})
  32. })
  33. }
  34. }
  35. })
  36. }
  37. #[derive(PartialEq, Props)]
  38. struct CompProps {
  39. color: &'static str,
  40. }
  41. fn Comp(cx: Scope<CompProps>) -> Element {
  42. cx.render(rsx! {
  43. h1 {
  44. color: "{cx.props.color}",
  45. "Hello, from a component!"
  46. }
  47. })
  48. }