2021-11-07 03:11:17 +00:00
|
|
|
use dioxus::prelude::*;
|
|
|
|
use dioxus_core as dioxus;
|
|
|
|
use dioxus_core_macro::*;
|
|
|
|
use dioxus_html as dioxus_elements;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
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);
|
|
|
|
|
|
|
|
cx.render(rsx! {
|
|
|
|
div {
|
|
|
|
Child { name: value }
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Props)]
|
|
|
|
struct ChildProps<'a> {
|
|
|
|
name: &'a str,
|
|
|
|
}
|
|
|
|
|
2021-11-08 01:59:09 +00:00
|
|
|
fn Child(cx: Context, props: &ChildProps) -> Element {
|
2021-11-07 03:11:17 +00:00
|
|
|
cx.render(rsx! {
|
|
|
|
div {
|
|
|
|
h1 { "it's nested" }
|
|
|
|
Child2 { name: props.name }
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Props)]
|
|
|
|
struct Grandchild<'a> {
|
|
|
|
name: &'a str,
|
|
|
|
}
|
|
|
|
|
2021-11-08 01:59:09 +00:00
|
|
|
fn Child2(cx: Context, props: &Grandchild) -> Element {
|
2021-11-07 03:11:17 +00:00
|
|
|
cx.render(rsx! {
|
|
|
|
div { "Hello {props.name}!" }
|
|
|
|
})
|
|
|
|
}
|