2021-10-22 05:16:39 +00:00
|
|
|
#![allow(non_snake_case)]
|
|
|
|
|
|
|
|
use dioxus::prelude::*;
|
2021-09-21 17:13:15 +00:00
|
|
|
use dioxus_core as dioxus;
|
2021-09-25 01:46:23 +00:00
|
|
|
use dioxus_core_macro::*;
|
2021-09-21 17:13:15 +00:00
|
|
|
use dioxus_html as dioxus_elements;
|
|
|
|
|
2021-10-22 05:16:39 +00:00
|
|
|
#[test]
|
|
|
|
fn test_borrowed_state() {
|
|
|
|
let _ = VirtualDom::new(Parent);
|
|
|
|
}
|
|
|
|
|
2021-11-08 01:59:09 +00:00
|
|
|
fn Parent(cx: Context, props: &()) -> Element {
|
2021-11-07 03:11:17 +00:00
|
|
|
let value = cx.use_hook(|_| String::new(), |f| &*f);
|
2021-09-21 17:13:15 +00:00
|
|
|
|
2021-10-30 22:23:28 +00:00
|
|
|
cx.render(rsx! {
|
2021-09-21 17:13:15 +00:00
|
|
|
div {
|
|
|
|
Child { name: value }
|
|
|
|
Child { name: value }
|
|
|
|
Child { name: value }
|
|
|
|
Child { name: value }
|
|
|
|
}
|
2021-10-30 22:23:28 +00:00
|
|
|
})
|
2021-10-22 05:16:39 +00:00
|
|
|
}
|
2021-09-21 17:13:15 +00:00
|
|
|
|
|
|
|
#[derive(Props)]
|
|
|
|
struct ChildProps<'a> {
|
2021-10-22 05:16:39 +00:00
|
|
|
name: &'a str,
|
2021-09-21 17:13:15 +00:00
|
|
|
}
|
|
|
|
|
2021-11-08 01:59:09 +00:00
|
|
|
fn Child(cx: Context, props: &ChildProps) -> Element {
|
2021-10-30 22:23:28 +00:00
|
|
|
cx.render(rsx! {
|
2021-09-21 17:13:15 +00:00
|
|
|
div {
|
|
|
|
h1 { "it's nested" }
|
|
|
|
Child2 { name: props.name }
|
|
|
|
}
|
2021-10-30 22:23:28 +00:00
|
|
|
})
|
2021-09-21 17:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Props)]
|
|
|
|
struct Grandchild<'a> {
|
2021-10-22 05:16:39 +00:00
|
|
|
name: &'a str,
|
2021-09-21 17:13:15 +00:00
|
|
|
}
|
|
|
|
|
2021-11-08 01:59:09 +00:00
|
|
|
fn Child2(cx: Context, props: &Grandchild) -> Element {
|
2021-10-30 22:23:28 +00:00
|
|
|
cx.render(rsx! {
|
2021-09-21 17:13:15 +00:00
|
|
|
div { "Hello {props.name}!" }
|
2021-10-30 22:23:28 +00:00
|
|
|
})
|
2021-09-21 17:13:15 +00:00
|
|
|
}
|