This is unreleased documentation for Yew Next version.
For up-to-date documentation, see the latest version on docs.rs.

Attribute Macro yew::functional::function_component

source ·
#[function_component]
Expand description

This attribute creates a function component from a normal Rust function.

Functions with this attribute must return Html and can optionally take an argument for props. Note that the function only receives a reference to the props.

When using this attribute you need to provide a name for the component: #[function_component(ComponentName)]. The attribute will then automatically create a [FunctionComponent] with the given identifier which you can use like a normal component.

§Example

#[function_component(NameOfComponent)]
pub fn component(props: &Props) -> Html {
    html! {
        <p>{ &props.text }</p>
    }
}