Learn by making
Small examples.
Real foundations.
Follow the state. See how the pieces fit.
The same Rust views, running in two places.
Install the CLI once. Run Counter and Chat from your Refract checkout. The CLI handles WASM setup and rebuilds on save. Native examples have been tested on macOS. Set up once →
Counter
A tiny application. A reactive foundation.
Declare a value, read it in a view, and update it from an action. This is the smallest useful loop in Refract.
use refract::prelude::*;
#[view]
fn counter(cx: &mut ViewContext<'_>, initial: u32) -> impl View {
#[state]
let count: u32 = initial;
#[action(count)]
let increment = |cx| {
count.update(cx.runtime(), |n| *n += 1);
};
view()
.child(text(format!("Count: {}", cx.read(&count))))
.padding(16.0)
.on_press(increment)
}refract dev -p refract-counter --openChat
Async replies. A responsive UI.
Searchable conversations, per-chat drafts, and local replies streamed through typed channels. Native worker threads and browser async tasks produce chunks; UI-side receivers update state. Replies continue when you switch chats, while Stop or deletion cancels their work. Replies are scripted, need no API key, and stay in this session.
- ↳Async work
- ↳Typed channels
- ↳Scoped cancellation
Refract checkoutexamples/chat/src/lib.rs
refract dev -p refract-chat --port 4176 --openBlock Editor
Rich text. Your own workspace.
Write with headings, lists, and tables. Format text, select across blocks, and undo edits. A Yrs document holds the content while Refract updates the affected fields. Each visitor gets a local workspace, with edits saved in their browser and no shared server.
- ↳Text editing
- ↳Selection & clipboard
- ↳Local persistence
Make it your own
Start building today.
Stacks, spacing, and paint are just Rust method calls. Start from an example, change a view, and build up from there.
Explore layout & stylingv_stack()
.gap(16.0)
.child(text("Hello, Refract").font_size(28.0))
.child(text("A shared view. A different host."))
.padding(24.0)
.background(Color::rgb(15, 30, 52))
.foreground(Color::WHITE)
.radius(12.0)