pub trait Component {
type Props;
// Required method
fn render(props: Self::Props) -> Node;
}Expand description
A trait for creating reusable components.
Components are the heart of RSX’s reusability model. They allow you to create custom elements with their own logic and state.
§Example
use simple_rsx::*;
struct Card;
#[derive(Default)]
struct CardProps {
title: String,
children: Vec<Node>,
}
impl Component for Card {
type Props = CardProps;
fn render(&mut self, props: Self::Props) -> Node {
rsx!(
<div class="card">
<h2>{props.title}</h2>
<div class="card-content">{props.children}</div>
</div>
)
}
}Required Associated Types§
Required Methods§
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.