01-counter

command
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: MIT Imports: 4 Imported by: 0

README

Counter Example

Level: Beginner
Concepts: Basic state management, event handling

What This Example Demonstrates

  • Using hooks.UseState for number state
  • Button click handlers with js.FuncOf
  • Simple increment/decrement operations
  • State updates triggering re-renders
  • Basic Tailwind CSS styling

Key Code

count, setCount := hooks.UseState(0)
currentCount := count()

increment := func(this js.Value, args []js.Value) interface{} {
    setCount(currentCount + 1)
    return nil
}

Learning Objectives

  1. Understand how to create and update state in GoWebComponents
  2. Learn to attach event handlers to DOM elements
  3. See how state changes trigger component re-renders
  4. Build interactive UI with functional programming patterns

Running

cd examples
./build.ps1 -Example 01-counter

Then open 01-counter/counter.html in a web server.

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