1
0

optional_props.rs 918 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #![allow(non_snake_case)]
  2. //! Example: README.md showcase
  3. //!
  4. //! The example from the README.md.
  5. use dioxus::prelude::*;
  6. fn main() {
  7. dioxus::desktop::launch(app);
  8. }
  9. fn app(cx: Scope) -> Element {
  10. cx.render(rsx! {
  11. Button {
  12. a: "asd".to_string(),
  13. c: Some("asd".to_string()),
  14. d: "asd".to_string(),
  15. e: "asd".to_string(),
  16. }
  17. })
  18. }
  19. #[derive(Props, PartialEq)]
  20. struct ButtonProps {
  21. a: String,
  22. #[props(default)]
  23. b: Option<String>,
  24. #[props(default)]
  25. c: Option<String>,
  26. #[props(default, strip_option)]
  27. d: Option<String>,
  28. #[props(optional)]
  29. e: Option<String>,
  30. }
  31. fn Button(cx: Scope<ButtonProps>) -> Element {
  32. cx.render(rsx! {
  33. button {
  34. "{cx.props.a}"
  35. "{cx.props.b:?}"
  36. "{cx.props.c:?}"
  37. "{cx.props.d:?}"
  38. "{cx.props.e:?}"
  39. }
  40. })
  41. }