basics.rs 810 B

12345678910111213141516171819202122232425262728293031323334353637
  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 static Example: FC<()> = |(cx, props)| {
  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 {
  22. name: &'static str,
  23. }
  24. static Greeting: FC<GreetingProps> = |(cx, props)| {
  25. cx.render(rsx! {
  26. div {
  27. h1 { "Hello, {props.name}!" }
  28. p { "Welcome to the Diouxs framework" }
  29. br {}
  30. {cx.children()}
  31. }
  32. })
  33. };