Attribute Macro function_component

Source
#[function_component]
Expand description

Implement component renderer.

A component takes input in the form of props and children, and return elements describing what should appear on the screen.

§Example

#[derive_component(Default,ComponentBuilder)]
pub struct MyComp {
    param1: i32,
    param2: i32
}

#[function_component]
fn _my_comp_render(props:MyComp)->Elements {
    apx! {
        <bg col=0x000000/>
    }
}

As should be evident by the _ prefix for the function, the actual function name is not important. Rather, the render function is tied to a specific type of element by type inference based on the parameter it takes.

The component declared above can be used together with the apx macro:

apx!{
    <MyComp param1=123 param2=456/>
}