works.rs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #![allow(non_snake_case)]
  2. use dioxus::prelude::*;
  3. use dioxus_core as dioxus;
  4. use dioxus_core_macro::*;
  5. use dioxus_html as dioxus_elements;
  6. fn main() {
  7. let _ = VirtualDom::new(parent);
  8. }
  9. fn parent(cx: Scope<()>) -> Element {
  10. let value = cx.use_hook(|_| String::new(), |f| f);
  11. cx.render(rsx! {
  12. div {
  13. child( name: value )
  14. }
  15. })
  16. }
  17. #[derive(Props)]
  18. struct ChildProps<'a> {
  19. name: &'a str,
  20. }
  21. fn child<'a>(cx: Scope<'a, ChildProps<'a>>) -> Element {
  22. cx.render(rsx! {
  23. div {
  24. h1 { "it's nested" }
  25. grandchild( name: cx.props.name )
  26. }
  27. })
  28. }
  29. #[derive(Props)]
  30. struct Grandchild<'a> {
  31. name: &'a str,
  32. }
  33. fn grandchild<'a>(cx: Scope<'a, Grandchild>) -> Element<'a> {
  34. cx.render(rsx! {
  35. div { "Hello {cx.props.name}!" }
  36. great_grandchild( name: cx.props.name )
  37. })
  38. }
  39. fn great_grandchild<'a>(cx: Scope<'a, Grandchild>) -> Element<'a> {
  40. cx.render(rsx! {
  41. div {
  42. h1 { "it's nested" }
  43. }
  44. })
  45. }
  46. /*
  47. can we implement memoization as a wrapper or something? Like we just intercept the
  48. render function?
  49. */