borrowedstate.rs 957 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. use dioxus::{nodes::VSuspended, prelude::*, DomEdit, TestDom};
  2. use dioxus_core as dioxus;
  3. use dioxus_core_macro::*;
  4. use dioxus_html as dioxus_elements;
  5. static Parent: FC<()> = |(cx, props)| {
  6. let value = cx.use_hook(|_| String::new(), |f| &*f, |_| {});
  7. cx.render(rsx! {
  8. div {
  9. Child { name: value }
  10. Child { name: value }
  11. Child { name: value }
  12. Child { name: value }
  13. }
  14. })
  15. };
  16. #[derive(Props)]
  17. struct ChildProps<'a> {
  18. name: &'a String,
  19. }
  20. fn Child<'a>((cx, props): Component<'a, ChildProps>) -> DomTree<'a> {
  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 String,
  31. }
  32. fn Child2<'a>((cx, props): Component<'a, Grandchild>) -> DomTree<'a> {
  33. cx.render(rsx! {
  34. div { "Hello {props.name}!" }
  35. })
  36. }
  37. #[test]
  38. fn test_borrowed_state() {}