hexops / vecty

Vecty lets you build responsive and dynamic web frontends in Go using WebAssembly, competing with modern web frameworks like React & VueJS.
BSD 3-Clause "New" or "Revised" License
2.8k stars 143 forks source link

Return type of If function #298

Open stas-makutin opened 2 years ago

stas-makutin commented 2 years ago

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
        )
}