2021-12-10 02:19:31 +00:00
|
|
|
#![allow(non_snake_case)]
|
|
|
|
|
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() {
|
2021-12-21 03:33:13 +00:00
|
|
|
let _ = VirtualDom::new(parent);
|
2021-11-07 03:11:17 +00:00
|
|
|
}
|
|
|
|
|
2021-12-30 02:28:28 +00:00
|
|
|
fn parent(cx: Scope) -> Element {
|
2022-01-02 07:15:04 +00:00
|
|
|
let value = cx.use_hook(|_| String::new());
|
2021-11-07 03:11:17 +00:00
|
|
|
|
|
|
|
cx.render(rsx! {
|
|
|
|
div {
|
2021-12-21 03:33:13 +00:00
|
|
|
child( name: value )
|
2021-11-07 03:11:17 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Props)]
|
|
|
|
struct ChildProps<'a> {
|
|
|
|
name: &'a str,
|
|
|
|
}
|
|
|
|
|
2021-12-21 03:33:13 +00:00
|
|
|
fn child<'a>(cx: Scope<'a, ChildProps<'a>>) -> Element {
|
2021-11-07 03:11:17 +00:00
|
|
|
cx.render(rsx! {
|
|
|
|
div {
|
|
|
|
h1 { "it's nested" }
|
2021-12-21 03:33:13 +00:00
|
|
|
grandchild( name: cx.props.name )
|
2021-11-07 03:11:17 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Props)]
|
|
|
|
struct Grandchild<'a> {
|
|
|
|
name: &'a str,
|
|
|
|
}
|
|
|
|
|
2021-12-21 03:33:13 +00:00
|
|
|
fn grandchild<'a>(cx: Scope<'a, Grandchild>) -> Element<'a> {
|
2021-11-07 03:11:17 +00:00
|
|
|
cx.render(rsx! {
|
2021-12-15 02:46:19 +00:00
|
|
|
div { "Hello {cx.props.name}!" }
|
2021-12-21 03:33:13 +00:00
|
|
|
great_grandchild( name: cx.props.name )
|
2021-11-07 03:11:17 +00:00
|
|
|
})
|
|
|
|
}
|
2021-12-21 03:33:13 +00:00
|
|
|
|
|
|
|
fn great_grandchild<'a>(cx: Scope<'a, Grandchild>) -> Element<'a> {
|
|
|
|
cx.render(rsx! {
|
|
|
|
div {
|
|
|
|
h1 { "it's nested" }
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|