Frontend Frameworks (Leptos / Yew)
Build web UIs entirely in Rust with Leptos or Yew on top of WASM.
Busca en todas las páginas de la documentación
Build web UIs entirely in Rust with Leptos or Yew on top of WASM.
use leptos::*;
#[component]
fn App() -> impl IntoView {
let (count, set_count) = create_signal(0);
view! {
<button on:click=move |_| set_count.update(|n| *n + 1)>
"Clicked " {count} " times"
</button>
}
}When to reach for this: Teams that want Rust end-to-end for web apps with component-based UI and fine-grained reactivity.
use leptos::*;
#[component]
fn Greeting(name: String) -> impl IntoView {
view! { <p>"Hello, " {name} "!"</p> }
}
#[component]
fn App() -> impl IntoView {
let (name, set_name) = create_signal(String::from("Rust"));
view! {
<input
prop:value=move || name.get()
on:input=move |ev| set_name.set(event_target_value(&ev))
/>
<Greeting name=name.get()/>
}
}
pub fn main() {
mount_to_body(|| view! { <App/> })
}What this demonstrates:
#[component]view! macro compiles to DOM operations| Framework | Model | Strength |
|---|---|---|
| Leptos | Fine-grained signals | Performance, SSR/hydration |
| Yew | Component virtual DOM | Mature ecosystem, HTML-like macros |
use yew::prelude::*;
#[function_component]
fn Counter() -> Html {
let counter = use_state(|| 0);
html! {
<button onclick={Callback::from(move |_| counter.set(*counter + 1))}>
{ *counter }
</button>
}
}my-app/
Cargo.toml # leptos or yew deps
src/lib.rs # components
index.html # mount point
Trunk.toml # Trunk bundler config (common)
wasm-opt, lazy routes.wasm-bindgen for specific libraries.leptos_router or yew-router.| Alternative | Use When | Don't Use When |
|---|---|---|
| React + WASM module | UI in JS, compute in Rust | Full Rust UI team |
| Svelte/Solid + WASM | Smaller JS UI bundles | Rust-only shop |
| web-sys direct | Tiny DOM utilities | Full application UI |
CSR mounts to empty HTML. SSR renders on server then hydrates in browser for faster first paint.
Tailwind via trunk, vanilla CSS, or stylers crate. No single standard yet.
Leptos signals and context. Yew uses hooks and context API similar to React.
Leptos leptos::mount_to_body in tests. Yew TestRenderer for unit tests.
reqwest with wasm-bindgen-futures or gloo-net for browser fetch.
Static hosting (Netlify, Cloudflare Pages) for CSR. SSR needs Rust server (Axum + Leptos).
Expose WASM compute crate to TS frontend, or go full Rust UI with frameworks here.
Use semantic HTML in view!/html!. Test with axe and keyboard navigation.
trunk serve and cargo leptos watch provide dev reload workflows.
Leptos for new full-stack Rust web apps. Yew if your team already invested in it.
Stack versions: This page was written for Rust 1.97.0 (edition 2024), Tokio 1.x, Axum 0.8, serde 1.0, sqlx 0.8, clap 4, and Polars 0.46+.
Revisado por Chris St. John·Última actualización: 16 jul 2026