Trait Properties

Source
pub trait Properties:
    Clone
    + Sized
    + 'static {
    type Builder;

    // Required methods
    fn builder() -> Self::Builder;
    fn memoize(&mut self, other: &Self) -> bool;

    // Provided method
    fn into_vcomponent<M: 'static>(
        self,
        render_fn: impl ComponentFunction<Self, M>,
    ) -> VComponent { ... }
}
Expand description

Every “Props” used for a component must implement the Properties trait. This trait gives some hints to Dioxus on how to memoize the props and some additional optimizations that can be made. We strongly encourage using the derive macro to implement the Properties trait automatically.

Dioxus requires your props to be ’static, Clone, and PartialEq. We use the PartialEq trait to determine if the props have changed when we diff the component.

§Example

#[derive(Props, PartialEq, Clone)]
struct MyComponentProps {
    data: String
}

fn MyComponent(props: MyComponentProps) -> Element {
    rsx! {
        div { "Hello {props.data}" }
    }
}

Or even better, derive your entire props struct with the [#[crate::component]] macro:

#[component]
fn MyComponent(data: String) -> Element {
    rsx! {
        div { "Hello {data}" }
    }
}

Required Associated Types§

Source

type Builder

The type of the builder for this component. Used to create “in-progress” versions of the props.

Required Methods§

Source

fn builder() -> Self::Builder

Create a builder for this component.

Source

fn memoize(&mut self, other: &Self) -> bool

Make the old props equal to the new props. Return if the props were equal and should be memoized.

Provided Methods§

Source

fn into_vcomponent<M: 'static>( self, render_fn: impl ComponentFunction<Self, M>, ) -> VComponent

Create a component from the props.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Properties for ()

Source§

type Builder = EmptyBuilder

Source§

fn builder() -> Self::Builder

Source§

fn memoize(&mut self, _other: &Self) -> bool

Implementors§

Source§

impl Properties for SuspenseBoundaryProps
where Self: Clone,

Source§

type Builder = SuspenseBoundaryPropsBuilder<((), ())>