Coming from
WebFluent for React developers
Most of what you know from React carries over: components with props, state, a router and shared stores. The difference to hold on to is that WebFluent is a compiler with typed markup, not a library: a component's body runs once, and only the text, attribute or style that reads a changed value updates. There are no hooks, no dependency arrays and no setters.
A value that changes
You write
const [n, setN] = useState(0)
In WebFluent
state n = 0
Changing it
You write
setN(n + 1)
In WebFluent
n = n + 1
A value worked out from others
You write
const total = useMemo(() => sum(items), [items])
In WebFluent
derived total = items.sum()
A side effect
You write
useEffect(() => { start(); return () => stop() }, [id])
In WebFluent
effect { start(id) cleanup { stop() } }
A handle on an element
You write
const box = useRef(null) … box.current.focus()
In WebFluent
Input(bind: q, ref: box) … box.focus()
A component
You write
function Card({ title }) { … }
In WebFluent
component Card(_ title: String) { … }
What the caller puts inside
You write
{props.children}
In WebFluent
children
A callback prop
You write
onChange={(v) => setLast(v)}
In WebFluent
event change(value: Number), handled as on change(value) { last = value }
A controlled input
You write
value={q} onChange={(e) => setQ(e.target.value)}
In WebFluent
Input(bind: q, label: "Search")
State shared across pages
You write
createContext, Redux, Zustand
In WebFluent
store Cart { … }, read as Cart.items after use Cart
A route
You write
<Route path="/users/:id" element={<User />} />
In WebFluent
page User(path: "/users/:id", id: String) { … }
Showing something conditionally
You write
{open && <Panel />}
In WebFluent
if open { Panel }
A list
You write
{items.map((i) => <li key={i.id}>{i.name}</li>)}
In WebFluent
for i in items by i.id { Text(i.name) }
Fetching
You write
TanStack Query's useQuery({ queryKey: ["users"], queryFn }), or useEffect + fetch
In WebFluent
resource users: [User] = http.get("/api/users"), read with match users { … }
Styling
You write
className, CSS modules, Tailwind
In WebFluent
flags (Button("Save").primary), style { } on the element, design tokens
A test
You write
Testing Library: render, fireEvent.click, getByText
In WebFluent
test "…" { click "Save" expect "Saved" }
Things that work differently
It is a compiler, not a library. There is no virtual DOM and no re-render. Each text, attribute or style that reads a state follows it on its own, and a component's body runs once, when it is placed. That is why there are no hooks and no rules about calling them in order.
The markup is typed. The compiler knows the props, flags, events and slots of every built-in and of every component you declare. Button("Save").primray does not build, and neither does a handler for an event the component never fires (E103). An unknown prop on your own component is C02, not a silent pass-through.
Typed without a second language. There is no TypeScript beside the markup and no tsc step: a .wf file is typed by the compiler that builds it. The checker infers what it can and asks you to write the rest: a state whose first value says nothing (state items: [Todo] = []), an action that returns (-> Number), a parameter. There is no any: JSON whose shape is open is Json, matched or decoded (User.decode(raw)) before it is read, and no setting turns the checks off.
Pages own their routes. There is no route table. Each page names its path:, and the compiler builds the router from them, ordered by specificity, so the order you declare pages in cannot hide a route.
No imports, no npm. Every file under src/ is part of one program, so a component declared anywhere is usable everywhere. A JavaScript library is a URL in meta.scripts, and your own JavaScript is a plain .js file under src/ whose functions .wf code calls by name (Call your own JavaScript).
The build is the site. Pre-rendering, code splitting, image resizing, a sitemap, link previews and a Content-Security-Policy come from wf build, with no plugins to choose. There is no server rendering on each request: a site is static files and a browser runtime, talking to your API.
Text is text. The only way to put markup on a page is Unsafe.Html(…), which the build flags every time, and inline handlers and javascript: URLs do not compile (Security).
Using it inside a React app. Publish components as custom elements and place their tags in JSX (Publish components as custom elements).
A component, ported
The same counter, in React and in WebFluent. It starts at a number the caller passes, counts up on a click, shows a badge when the count is even, and tells the caller about each change.
function Counter({ start = 0, onChange }) {
const [n, setN] = useState(start);
const even = useMemo(() => n % 2 === 0, [n]);
return (
<div className="row">
<button onClick={() => { setN(n + 1); onChange?.(n + 1); }}>+</button>
<span>{n}</span>
{even && <span className="badge">even</span>}
</div>
);
}
page Scores(path: "/", title: "Scores", description: "A counter that reports each change.") {
state last = 0
Heading("Scores").h1
Counter(start: 2) { on change(value) { last = value } }
Text("Last change: {last}")
}
component Counter(start: Number = 0) {
event change(value: Number)
state n = start
derived even = n % 2 == 0
Row(gap: .sm, align: .center) {
Button("+") { on click { n = n + 1 emit change(n) } }
Text("{n}")
if even { Badge("even").info }
}
}
- No hooks and no dependency arrays.
derivedknows what it reads. - No setter. You assign:
n = n + 1. - No
className.Badgecomes designed, and.infois a flag the compiler checks. - The event is declared. A caller that handles
on chnagegetsE103at build time, instead of a handler that never runs.