counter

command
v4.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 5 Imported by: 0

README

Counter Example

Level: Beginner
Concepts: ui.UseState, ui.UseEvent, declarative event wiring, rerender on state change

Current Status

This example is the smallest current interactive app in the integrated example set.

It demonstrates the modern ui package hook surface rather than the older hooks.* API shape, and it is useful as the first stop when you want to see a minimal browser-mounted GoWebComponents component with local state.

What This Example Demonstrates

  • Using ui.UseState for local numeric state
  • Using ui.UseEvent for typed click handlers without raw syscall/js wiring
  • Increment, decrement, and reset flows through count.Update(...) and count.Set(...)
  • State-driven rerendering in a minimal component
  • A small but intentionally styled integrated example shell

Key Code

count := ui.UseState(0)
currentCount := count.Get()

increment := ui.UseEvent(func() {
    count.Update(func(prev int) int { return prev + 1 })
})

Learning Objectives

  1. Understand how to create and update local state with ui.UseState
  2. Learn how event handlers are attached through ui.UseEvent
  3. See how state updates trigger rerendering without manual DOM mutation
  4. Use a very small example as the entrypoint into the larger examples catalog

Running

From the repo root, preferred current paths are:

go run ./tools/gwc examples

Then open http://127.0.0.1:8090/examples/public/counter/counter.html.

  • examples/README.md
  • docs/REFERENCE_MANUAL/01-getting-started.md
  • docs/REFERENCE_MANUAL/02-gwc-workflows.md

Documentation

Rendered for js/wasm
The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL