Skip to main content

component

Attribute Macro component 

Source
#[component]
Expand description

Publishes an implementation’s lifecycle hooks and actions to the browser.

ⓘ
#[component]
impl Counter {
    fn mount(&mut self, count: Option<i32>) {
        self.count = count.unwrap_or(0);
    }

    fn increment(&mut self, by: i32) {
        self.count += by;
    }
}

Class options go on the attribute: layout = "…", title = "…", transition = "…", lazy, defer, and isolate. Method options go on the method:

Method attributeMeaning
on = "event"The method listens for the event
renderlessThe method’s response carries no HTML
jsonThe method answers with JSON
asyncThe browser sends the call ahead of the others
authorize(path::to::policy)The policy decides whether the call may run