Skip to main content

ComponentFunction

Trait ComponentFunction 

Source
pub trait ComponentFunction<Props, Marker = ()>: Clone + 'static {
    // Required methods
    fn fn_ptr(&self) -> usize;
    fn rebuild(&self, props: Props) -> Element;
}
Expand description

Any component that implements the ComponentFn trait can be used as a component.

This trait is automatically implemented for functions that are in one of the following forms:

  • fn() -> Element
  • fn(props: Properties) -> Element

You can derive it automatically for any function with arguments that implement PartialEq with the #[component] attribute:

#[component]
fn MyComponent(a: u32, b: u32) -> Element {
    rsx! { "a: {a}, b: {b}" }
}

Required Methods§

Source

fn fn_ptr(&self) -> usize

Get the raw address of the component render function.

Source

fn rebuild(&self, props: Props) -> Element

Convert the component to a function that takes props and returns an element.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<F, P> ComponentFunction<P> for F
where F: Fn(P) -> Element + Clone + 'static,

Accept any callbacks that take props