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§
Required Methods§
Provided Methods§
sourcefn into_vcomponent<M>(
self,
render_fn: impl ComponentFunction<Self, M>,
) -> VComponentwhere
M: 'static,
fn into_vcomponent<M>(
self,
render_fn: impl ComponentFunction<Self, M>,
) -> VComponentwhere
M: 'static,
Create a component from the props.
Object Safety§
This trait is not object safe.