Type Definition dioxus_core::prelude::Component[][src]

pub type Component<P = ()> = fn(_: Scope<'_, P>) -> Element<'_>;
Expand description

A Component is a function that takes a Scope and returns an Element.

Components can be used in other components with two syntax options:

  • lowercase as a function call with named arguments (rust style)
  • uppercase as an element (react style)

Rust-Style

fn example(cx: Scope<Props>) -> Element {
    // ...
}

rsx!(
    example()
)

React-Style

fn Example(cx: Scope<Props>) -> Element {
    // ...
}

rsx!(
    Example {}
)

As a closure

This particular type alias lets you even use static closures for pure/static components:

static Example: Component<Props> = |cx| {
    // ...
};