component_owned_props.rs 591 B

12345678910111213141516171819202122232425262728293031323334
  1. #![allow(non_snake_case)]
  2. use dioxus::prelude::*;
  3. fn main() {
  4. dioxus_desktop::launch(App);
  5. }
  6. // ANCHOR: App
  7. fn App(cx: Scope) -> Element {
  8. cx.render(rsx! {
  9. Likes {
  10. score: 42,
  11. },
  12. })
  13. }
  14. // ANCHOR_END: App
  15. // ANCHOR: Likes
  16. // Remember: Owned props must implement `PartialEq`!
  17. #[derive(PartialEq, Props)]
  18. struct LikesProps {
  19. score: i32,
  20. }
  21. fn Likes(cx: Scope<LikesProps>) -> Element {
  22. cx.render(rsx! {
  23. div {
  24. "This post has ",
  25. b { "{cx.props.score}" },
  26. " likes"
  27. }
  28. })
  29. }
  30. // ANCHOR_END: Likes