Trait wasm_react::Component
source · [−]pub trait Component: 'static {
fn render(&self) -> VNode;
fn build(self) -> VNode
where
Self: Sized,
{ ... }
fn build_with_key(self, key: Option<&str>) -> VNode
where
Self: Sized,
{ ... }
}
Expand description
Implement this trait on a struct to create a component with the struct as props.
The props will be completely controlled by Rust, which makes rendering them
relatively simple in Rust. However, since the props struct cannot be
constructed in JS, these components cannot be exposed to JS. This means only
components written in Rust can render a Component
by default.
See export_components!
for how to expose
components for JS consumption.
Example
struct Counter(i32);
impl Component for Counter {
fn render(&self) -> VNode {
h!(div).build(c!["Counter: ", self.0])
}
}
Required Methods
The render function.
Do not call this method in another render function. Instead, use
Component::build()
to include your component.
Provided Methods
Returns a VNode
to be included in a render function.