works.rs 787 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. use dioxus::prelude::*;
  2. use dioxus_core as dioxus;
  3. use dioxus_core_macro::*;
  4. use dioxus_html as dioxus_elements;
  5. fn main() {
  6. let _ = VirtualDom::new(Parent);
  7. }
  8. fn Parent((cx, _): Scope<()>) -> Element {
  9. let value = cx.use_hook(|_| String::new(), |f| &*f);
  10. cx.render(rsx! {
  11. div {
  12. Child { name: value }
  13. }
  14. })
  15. }
  16. #[derive(Props)]
  17. struct ChildProps<'a> {
  18. name: &'a str,
  19. }
  20. fn Child((cx, props): Scope<ChildProps>) -> Element {
  21. cx.render(rsx! {
  22. div {
  23. h1 { "it's nested" }
  24. Child2 { name: props.name }
  25. }
  26. })
  27. }
  28. #[derive(Props)]
  29. struct Grandchild<'a> {
  30. name: &'a str,
  31. }
  32. fn Child2((cx, props): Scope<Grandchild>) -> Element {
  33. cx.render(rsx! {
  34. div { "Hello {props.name}!" }
  35. })
  36. }