dioxus_lib::prelude

Trait Properties

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

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

    // Provided method
    fn into_vcomponent<M>(
        self,
        render_fn: impl ComponentFunction<Self, M>,
    ) -> VComponent
       where M: 'static { ... }
}
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>( self, render_fn: impl ComponentFunction<Self, M>, ) -> VComponent
where M: 'static,

Create a component from the props.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Properties for ()

source§

type Builder = EmptyBuilder

source§

fn builder() -> <() as Properties>::Builder

source§

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

source§

impl Properties for LinkProps

source§

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

source§

fn builder() -> <LinkProps as Properties>::Builder

source§

fn memoize(&mut self, new: &LinkProps) -> bool

source§

impl Properties for MetaProps

source§

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

source§

fn builder() -> <MetaProps as Properties>::Builder

source§

fn memoize(&mut self, new: &MetaProps) -> bool

source§

impl Properties for ScriptProps

source§

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

source§

fn builder() -> <ScriptProps as Properties>::Builder

source§

fn memoize(&mut self, new: &ScriptProps) -> bool

source§

impl Properties for StyleProps

source§

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

source§

fn builder() -> <StyleProps as Properties>::Builder

source§

fn memoize(&mut self, new: &StyleProps) -> bool

source§

impl Properties for TitleProps

source§

type Builder = TitlePropsBuilder<((),)>

source§

fn builder() -> <TitleProps as Properties>::Builder

source§

fn memoize(&mut self, new: &TitleProps) -> bool

Implementors§

source§

impl Properties for SuspenseBoundaryProps

source§

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