Yew — Rust WASM Framework for Web Applications
Yew is a Rust framework for creating reliable and efficient web applications that compile to WebAssembly. Component-based with a virtual DOM, hooks, and familiar React-like API. Write your entire frontend in Rust with type safety and performance.
Instalación lista para agent
Este activo puede instalarse después de elegir el runtime, revisar el plan y ejecutar el comando correspondiente.
npx -y tokrepo@latest install ce6e1482-3651-11f1-9bc6-00163e2b0d79 --target codexEjecutar después de confirmar el plan con dry-run.
What it is
Yew is a Rust framework for creating reliable and efficient web applications that compile to WebAssembly. It provides a component-based architecture with a virtual DOM, hooks (use_state, use_effect, use_context), properties for data passing, and an event system. Yew's API is inspired by React, making it accessible to developers familiar with modern frontend patterns.
Yew targets Rust developers who want to build frontend web applications with the same language they use for backends, CLI tools, and systems programming. It suits single-page applications, interactive dashboards, and web-based tools where Rust's performance and type safety are advantages.
How it saves time or tokens
Yew's component model and hooks eliminate the need for JavaScript for interactive web UIs. Rust's type system catches errors at compile time that JavaScript would only reveal at runtime. The virtual DOM efficiently updates only changed parts of the UI. Trunk (the recommended build tool) handles WASM compilation, asset bundling, and development server with hot reload.
For AI-assisted development, Yew's React-like patterns (components, props, hooks) are familiar to LLMs, making code generation productive.
How to use
- Install Trunk:
cargo install trunkand add the WASM target:rustup target add wasm32-unknown-unknown. - Create a project with Cargo, add
yewas a dependency. - Build and serve:
trunk servefor development.
Example
use yew::prelude::*;
#[function_component(App)]
fn app() -> Html {
let counter = use_state(|| 0);
let onclick = {
let counter = counter.clone();
Callback::from(move |_| counter.set(*counter + 1))
};
html! {
<div>
<h1>{ "Counter" }</h1>
<p>{ format!("Count: {}", *counter) }</p>
<button {onclick}>{ "Increment" }</button>
</div>
}
}
fn main() {
yew::Renderer::<App>::new().render();
}
Related on TokRepo
- AI coding tools -- Rust and web development frameworks
- Featured workflows -- discover top curated assets on TokRepo
Common pitfalls
- Expecting npm package compatibility. Yew runs in WASM, not Node.js. JavaScript interop requires wasm-bindgen and web-sys crates, not npm packages.
- Large WASM binary sizes. Use
wasm-optand enable LTO in release builds to reduce binary size. Initial download is larger than equivalent JavaScript. - Thinking Yew replaces all JavaScript. DOM APIs not exposed by web-sys may require JavaScript glue code. CSS frameworks and existing JS libraries need wasm-bindgen interop.
Preguntas frecuentes
Yew is web-only (WASM) and has been around longer with a more mature ecosystem. Dioxus is multi-platform (web, desktop, mobile, TUI) and is newer. Yew uses an html! macro; Dioxus uses rsx!. Both provide React-like component models. For web-only projects, both work well; Yew has more community resources. For multi-platform, Dioxus is the better choice.
Yew is one of the most mature Rust WASM frameworks with a stable API and active community. Several projects use Yew in production. The main concerns are WASM binary size (larger initial download than JS) and the smaller ecosystem compared to React or Vue. For internal tools and applications where Rust's safety matters, Yew is a viable choice.
Yew provides the yew-router crate for client-side routing. Define routes as an enum, implement the Routable trait, and use the Switch component to render different components based on the URL. The router supports nested routes, query parameters, and programmatic navigation.
WebAssembly executes at near-native speed, making compute-heavy operations (data processing, canvas rendering, encryption) faster than JavaScript. For typical DOM manipulation, the performance difference is smaller because DOM operations are the bottleneck, not computation. Yew's virtual DOM minimizes DOM updates, which is where most UI frameworks spend time.
Yes. Use wasm-bindgen and js-sys/web-sys crates to call JavaScript functions from Rust. For existing JavaScript libraries (charting, maps, animations), create Rust bindings with wasm-bindgen that call the JS API. This enables gradual adoption where Yew handles the app structure while JS libraries provide specialized UI components.
Referencias (3)
- Yew Official Website— Yew is a Rust framework for web apps compiled to WebAssembly
- Yew Documentation— Yew documentation and tutorial
- Yew GitHub— Yew GitHub repository
Relacionados en TokRepo
Discusión
Activos relacionados
Xberg — Polyglot Document Intelligence Framework in Rust
A cross-language document extraction framework with a Rust core that parses PDFs, Office files, images, and 97+ formats into structured text and metadata.
Semantic UI — Human-Friendly UI Component Framework
Semantic UI is a front-end component framework that uses human-friendly HTML class names to create responsive, themeable layouts. It provides over 50 UI components designed around natural language principles.
Uno Platform — Pixel-Perfect Multi-Platform Apps with .NET
Build native mobile, desktop, and web applications from a single C# and XAML codebase targeting Windows, iOS, Android, macOS, Linux, and WebAssembly with pixel-perfect fidelity.
Pomerium — Identity-Aware Zero Trust Access Proxy
Pomerium is an open source reverse proxy that provides secure, identity-aware access to internal applications without a VPN, implementing BeyondCorp-style zero trust networking with SSO integration.