メインコンテンツまでスキップ
Version: 0.20

Children

Children is a special prop type that allows you to receive nested Html that is provided like html child elements.

use yew::{function_component, html, Html, Properties, Children};

#[function_component]
fn App() -> Html {
html! {
<HelloWorld>
<span>{"Hey what is up ;)"}</span>
<h1>{"THE SKY"}</h1>
</HelloWorld>
}
}

#[derive(Properties, PartialEq)]
pub struct Props {
pub children: Children, // the field name `children` is important!
}

#[function_component]
fn HelloWorld(props: &Props) -> Html {
html! {
<div class="very-stylized-container">
{ for props.children.iter() } // you can forward children like this
</div>
}
}

Further reading