Skip to content
This repository was archived by the owner on Mar 25, 2026. It is now read-only.
This repository was archived by the owner on Mar 25, 2026. It is now read-only.

Return type of If function #298

Description

@stas-makutin

Is it possible to change the return type of func If(cond bool, children ...ComponentOrHTML) MarkupOrChild to List?

This is my use case:

type CustomComponent struct {
 	vecty.Core
	Content vecty.List `vecty:"prop"`
}

func NewCustomComponent(content ...vecty.ComponentOrHTML) *CustomComponent {
	return &CustomComponent {Content: content}
}

func (ch *CustomComponent) Render() vecty.ComponentOrHTML {
	return elem.Div(
            ch.Content
        )
}

---

type View struct {
 	vecty.Core
        Flag bool
}

func (ch *View) Render() vecty.ComponentOrHTML {
	return NewCustomComponent(
                vecty.If(ch.Flag, elem.Div())      // will not compile
        )
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions