dioxus/packages/core/examples/component_children.rs

41 lines
748 B
Rust
Raw Normal View History

2021-12-21 05:46:10 +00:00
#![allow(non_snake_case)]
use dioxus::prelude::*;
use dioxus_core as dioxus;
use dioxus_core_macro::*;
use dioxus_html as dioxus_elements;
fn main() {
let mut dom = VirtualDom::new(parent);
let edits = dom.rebuild();
dbg!(edits);
}
2021-12-30 02:28:28 +00:00
fn parent(cx: Scope) -> Element {
let value = cx.use_hook(|_| String::new());
2021-12-21 05:46:10 +00:00
cx.render(rsx! {
div {
child(
name: value,
h1 {"hi"}
)
}
})
}
#[derive(Props)]
struct ChildProps<'a> {
name: &'a str,
children: Element<'a>,
}
fn child<'a>(cx: Scope<'a, ChildProps<'a>>) -> Element {
cx.render(rsx! {
div {
"it's nested {cx.props.name}",
&cx.props.children
2021-12-21 05:46:10 +00:00
}
})
}