// Copyright 2024, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 package main import ( "context" "fmt" "log" "github.com/wavetermdev/thenextwave/pkg/vdom" "github.com/wavetermdev/thenextwave/pkg/wshutil" ) func Page(ctx context.Context, props map[string]any) any { clicked, setClicked := vdom.UseState(ctx, false) var clickedDiv *vdom.Elem if clicked { clickedDiv = vdom.Bind(`
clicked
`, nil) } clickFn := func() { log.Printf("run clickFn\n") setClicked(true) } return vdom.Bind( `

hello world

`, map[string]any{"clickFn": clickFn, "clickedDiv": clickedDiv}, ) } func Button(ctx context.Context, props map[string]any) any { ref := vdom.UseRef(ctx, nil) clName, setClName := vdom.UseState(ctx, "button") vdom.UseEffect(ctx, func() func() { fmt.Printf("Button useEffect\n") setClName("button mounted") return nil }, nil) return vdom.Bind(`
`, map[string]any{"clName": clName, "ref": ref, "onClick": props["onClick"], "children": props["children"]}) } func main() { wshutil.SetTermRawModeAndInstallShutdownHandlers(true) defer wshutil.RestoreTermState() }