---
title: "oneui"
url: https://recursiveai.org/oneui/go/docs/overview/
description: "The module README: what oneui for Go is, state and generated code, testing a component, rendering to HTML and the browser backend."
version: "1.0.1"
source: https://github.com/recursive-ai-oss/oneui-go/blob/04fd4bf6ef9f3e6d03814514394ee2dfc4b559a7/README.md
---

# oneui

A pure-Go component model. A component is an HTML template, optional scoped CSS and a Go struct; `oneui generate` compiles it into plain Go that updates only the nodes bound to changed state, and emits a backend-neutral change-set stream. Includes a reference DOM with selector and accessibility queries, an engine-free retained UI tree, and a browser backend for `GOOS=js GOARCH=wasm`.

Licence: MIT OR Apache-2.0.

## Quick start

A component is a template next to a Go struct. `Hello.html`:

```html
<button on:click="Increment">Clicked {Count} times</button>
```

`main.go`:

```go
package main

//go:generate go run recursiveai.org/go/oneui/cmd/oneui generate

import (
	"os"

	"recursiveai.org/go/oneui"
)

type Hello struct {
	oneui.Base
	Count int `oneui:"state"`
}

func (h *Hello) Increment() { h.SetCount(h.Count + 1) }

func main() {
	h := &Hello{}
	h.Increment()
	oneui.RenderHTML(os.Stdout, h)
}
```

```sh
go mod init example.com/hello
go get recursiveai.org/go/oneui@v1.0.0
go generate ./...
go run .
# <button>Clicked 1 times</button>
```

`go generate` writes `Hello_oneui.go` with `SetCount` and the code that updates only the button's text when `Count` changes. The same component runs in a test (below), in the browser and in any backend that applies change sets.

## State and generated code

A field tagged `oneui:"state"` gets two generated methods: `SetX` replaces the value (and updates the bound nodes only when it changed, for types Go can compare; for slices, maps and structs holding them it always updates) and `NotifyXChanged` tells the component the value was changed in place. Generated files call the support package `rt`, which is versioned with the generator and is outside the compatibility promise: regenerate after upgrading. A generated file built against another runtime version stops at start-up with a message that says so.

## Testing a component

`oneui/oneuitest` mounts a component in the reference document, with a manual clock:

```go
page := oneuitest.Mount(t, &counter.Counter{})
page.Click("button")
if got := page.Text("button"); got != "Clicked 1 times" {
	t.Fatal(got)
}
```

## Rendering to HTML

Every generated component has `RenderHTML(w io.Writer) error`, and `oneui.RenderHTML(w, c)` does the same for any `oneui.Component`: the markup for the current state, written without creating nodes, for first paint or server-side rendering. Read "RenderHTML or mount?" on `oneui.HTMLRenderer` first: a child shows its default state, nothing a user typed is in the markup, no lifecycle callbacks run, stylesheets and listeners are not emitted, and mounting over the markup is not supported (no hydration). Bound values are written as the HTML attribute with the same meaning (`value`, `checked`).

## In the browser

`recursiveai.org/go/oneui/browser` (`GOOS=js GOARCH=wasm`) applies change sets to the page's real DOM, routes DOM events back to your handlers and registers components as custom elements:

```go
func main() {
	browser.Define("x-counter", func() oneui.Component { return &counter.Counter{} })
	select {} // the page drives the program from here on
}
```

`examples/browser` builds and runs it (`./build.sh`, then serve the folder). The browser package's tests (`browser/host_js_test.go`) run in a real page: build the test binary with `GOOS=js GOARCH=wasm go test -c ./browser` and host it, with Go's `wasm_exec.js`, in a headless browser.

## Speed

A 1,000-row list against templ and go-app, each checked to produce the same markup first (`bench/METHOD.md`, `bench/RESULTS.md`; AMD Ryzen 9 7950X3D, Go 1.26, six counts):

| | oneui | templ | go-app |
|---|---:|---:|---:|
| Render to HTML | 28.3 µs | 537 µs | 1.11 ms |
| Update one row, live (change set) | 13.9 µs | — | — |
| Update one row, server re-render | 29.1 µs | 471 µs | 1.08 ms |
| Update all rows, server re-render | 29.5 µs | 500 µs | 1.18 ms |
