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§
Required Methods§
Provided Methods§
Sourcefn into_vcomponent<M: 'static>(
self,
render_fn: impl ComponentFunction<Self, M>,
) -> VComponent
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.