pub trait Component {
type Props;
// Required method
fn render(&mut self, 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§
Implementations on Foreign Types§
Source§impl<P> Component for fn(P) -> Node
Implements Component for functions that take props and return a Node.
impl<P> Component for fn(P) -> Node
Implements Component for functions that take props and return a Node.
This allows you to use simple functions as components.
§Example
use simple_rsx::*;
fn Button(text: String) -> Node {
rsx!(<button>{text}</button>)
}