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>,
        component_name: &'static str
    ) -> 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 as guarantee that your memoization strategy is safe.

If your props are ’static, then Dioxus will require that they also be PartialEq for the derived memoize strategy.

By default, the memoization strategy is very conservative, but can be tuned to be more aggressive manually. However, this is only safe if the props are ’static - otherwise you might borrow references after-free.

We strongly suggest that any changes to memoization be done at the “PartialEq” level for ’static props. Additionally, we advise the use of smart pointers in cases where memoization is important.

§Example

For props that are ’static:

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

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>, component_name: &'static str ) -> VComponent

Create a component from the props.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Properties for ()

§

type Builder = EmptyBuilder

source§

fn builder() -> Self::Builder

source§

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

Implementors§