shorthand.rs 985 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. use dioxus::prelude::*;
  2. fn main() {
  3. launch_desktop(app);
  4. }
  5. fn app() -> Element {
  6. let a = 123;
  7. let b = 456;
  8. let c = 789;
  9. let class = "class";
  10. let id = "id";
  11. // todo: i'd like it for children on elements to be inferred as the children of the element
  12. // also should shorthands understand references/dereferences?
  13. // ie **a, *a, &a, &mut a, etc
  14. let children = render! { "Child" };
  15. let onclick = move |_| println!("Clicked!");
  16. render! {
  17. div { class, id, {&children} }
  18. Component { a, b, c, children, onclick }
  19. Component { a, ..ComponentProps { a: 1, b: 2, c: 3, children: None, onclick: Default::default() } }
  20. }
  21. }
  22. #[component]
  23. fn Component(a: i32, b: i32, c: i32, children: Element, onclick: EventHandler<()>) -> Element {
  24. render! {
  25. div { "{a}" }
  26. div { "{b}" }
  27. div { "{c}" }
  28. div { {children} }
  29. div {
  30. onclick: move |_| onclick.call(()),
  31. }
  32. }
  33. }