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

Attribute Macro 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>
    }
}