about summary refs log tree commit diff stats
path: root/gomponents_test.go
diff options
context:
space:
mode:
authorMarkus Wüstenberg2024-06-25 13:46:24 +0200
committerGitHub2024-06-25 13:46:24 +0200
commit1c0ceb44a530632be2d591eafcadea2ba481a682 (patch)
treeb61cc5295dd71ea337ed118a0834e81a80c3dd7d /gomponents_test.go
parentd9708f9290f723dd4424f86d300b18974e2c169b (diff)
downloadgomponents-1c0ceb44a530632be2d591eafcadea2ba481a682.tar.lz
gomponents-1c0ceb44a530632be2d591eafcadea2ba481a682.tar.zst
gomponents-1c0ceb44a530632be2d591eafcadea2ba481a682.zip
Adjust documentation on Iff (#179)
Diffstat (limited to 'gomponents_test.go')
-rw-r--r--gomponents_test.go14
1 files changed, 10 insertions, 4 deletions
diff --git a/gomponents_test.go b/gomponents_test.go
index df5da4f..c0ae7a7 100644
--- a/gomponents_test.go
+++ b/gomponents_test.go
@@ -277,10 +277,12 @@ func TestIf(t *testing.T) {
 
 func ExampleIf() {
 	showMessage := true
+
 	e := g.El("div",
 		g.If(showMessage, g.El("span", g.Text("You lost your hat!"))),
 		g.If(!showMessage, g.El("span", g.Text("No messages."))),
 	)
+
 	_ = e.Render(os.Stdout)
 	// Output: <div><span>You lost your hat!</span></div>
 }
@@ -302,14 +304,18 @@ func TestIff(t *testing.T) {
 }
 
 func ExampleIff() {
-	var nillableVariable *struct {
-		str string
+	type User struct {
+		Name string
 	}
+	var user *User
+
 	e := g.El("div",
-		g.Iff(nillableVariable != nil, func() g.Node {
-			return g.Text(nillableVariable.str)
+		// This would panic using just If
+		g.Iff(user != nil, func() g.Node {
+			return g.Text(user.Name)
 		}),
 	)
+
 	_ = e.Render(os.Stdout)
 	// Output: <div></div>
 }