pub trait Component {
// Required method
fn body(&self) -> impl View;
}Expand description
A component composed from other views, SwiftUI style.
Keep state in the struct’s fields (e.g. State<T>, created once in a
constructor); body is called on every rebuild and must not create state.
use ravenrs_reactive::State;
use ravenrs_widgets::{Button, Component, Text, VStack, View};
struct Counter {
count: State<i32>,
}
impl Component for Counter {
fn body(&self) -> impl View {
let count = self.count.clone();
VStack::new((
Text::bound(&self.count, |c| format!("Count: {c}")),
Button::new("Increment").on_click(move || count.update(|c| *c += 1)),
))
}
}Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".