A high-performance reactive user-interface framework for Rust. This crate provides a generic library that lets you define UI using declarative, type-safe syntax. Views combine together to form a statically-typed view tree that can be stored on the stack, giving this architecture its high performance.
struct Counter {
initial: i32,
}
impl View for Counter {
fn body(&self, cx: &Scope) -> impl View {
let (count, set_count) = use_state(cx, || self.initial);
(
text(format!("High five count: {}", count)),
div(text("Up high!")).on_click({
clone!(count, set_count);
move || set_count.set(count + 1)
}),
div(text("Down low!")).on_click({
clone!(count);
move || set_count.set(count - 1)
}),
)
}
}
#[derive(Clone)]
struct App;
impl View for App {
fn body(&self, _cx: &Scope) -> impl View {
(Counter { initial: 0 }, Counter { initial: 100 })
}
}
This crate is inspired by Xilem and uses a similar approach to type-safe reactivity. The main difference with this crate is the concept of scopes, components store their state in their own scope and updates to that scope re-render the component.
State management is inspired by React and Dioxus.