basics.rs 853 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. //! Example: The basics of Dioxus
  2. //! ----------------------------
  3. //!
  4. //! This small example covers some of the basics of Dioxus including
  5. //! - Components
  6. //! - Props
  7. //! - Children
  8. //! - the rsx! macro
  9. use dioxus::prelude::*;
  10. pub fn Example(cx: Scope) -> Element {
  11. cx.render(rsx! {
  12. div {
  13. Greeting {
  14. name: "Dioxus"
  15. div { "Dioxus is a fun, fast, and portable UI framework for Rust" }
  16. }
  17. }
  18. })
  19. }
  20. #[derive(PartialEq, Props)]
  21. struct GreetingProps<'a> {
  22. name: &'static str,
  23. children: Element<'a>,
  24. }
  25. pub fn Greeting<'a>(cx: Scope<'a, GreetingProps<'a>>) -> Element {
  26. cx.render(rsx! {
  27. div {
  28. h1 { "Hello, {cx.props.name}!" }
  29. p { "Welcome to the Dioxus framework" }
  30. br {}
  31. &cx.props.children
  32. }
  33. })
  34. }