1
0

shorthand.rs 1.0 KB

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