SkillsApr 12, 2026·2 min read

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.

Agent ready

Ready-to-run agent install

This asset can be installed after the agent chooses its runtime, checks the plan, and runs the matching command.

Native · 98/100Policy: allow
Agent surface
Any MCP/CLI agent
Kind
Skill
Install
Single
Trust
Trust: Established
Entrypoint
step-1.md
Direct install command
npx -y tokrepo@latest install ce6e1482-3651-11f1-9bc6-00163e2b0d79 --target codex

Run after dry-run confirms the install plan.

TL;DR
Yew compiles Rust to WebAssembly for building web applications with a component-based virtual DOM, hooks, and a React-like developer experience.
§01

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.

§02

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.

§03

How to use

  1. Install Trunk: cargo install trunk and add the WASM target: rustup target add wasm32-unknown-unknown.
  2. Create a project with Cargo, add yew as a dependency.
  3. Build and serve: trunk serve for development.
§04

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();
}
§05

Related on TokRepo

§06

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-opt and 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.

Frequently Asked Questions

How does Yew compare to Dioxus?+

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.

Is Yew production-ready?+

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.

How does Yew handle routing?+

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.

What is the performance benefit of Yew?+

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.

Can Yew call JavaScript libraries?+

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.

Citations (3)

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets