[][src]Attribute Macro render_macros::component

#[component]

A syntactic sugar for implementing Render conveniently using functions.

This attribute should be above a stand-alone function definition that returns a String:

#[component]
fn UserFn(name: String) {
    rsx! { <div>{format!("Hello, {}", name)}</div> }
}

Practically, this is exactly the same as using the Render trait:

#[derive(Debug)]
struct User { name: String }

impl render::Render for User {
    fn render_into<W: std::fmt::Write>(self, writer: &mut W) -> std::fmt::Result {
        Render::render_into(rsx! { <div>{format!("Hello, {}", self.name)}</div> }, writer)
    }
}