Skip to main content

component

Attribute Macro component 

Source
#[component]
Expand description

Turn a function into a egui-reactor component.

ⓘ
#[component]
fn Counter(cx: &mut Cx, initial: i32, label: Option<&str>, #[event] on_change: i32) {
    ..
}

Generates a CounterProps struct with a typed builder, an optional CounterEvent enum (one variant per #[event] argument) and a Counter(cx, props) function. The body’s tail expression is shown as a View.

Argument attributes:

  • #[prop(default)] / #[prop(default = expr)]: optional prop.
  • #[prop(into)]: the setter takes impl Into<T>.
  • #[event]: becomes an Emitter in the body and a variant in the event enum.

An argument of type Option<T> is optional without any attribute. An argument named children receives the child nodes; if it is not declared, one of type () is generated, because rsx! always passes children.