Closed markuswustenberg closed 1 month ago
@EwenQuim could you elaborate what this means? How would you use it?
The way I build components, they look like this:
func SomeComponent(ctx SomeContext) Node {
return Div(Span(ctx.Whatever))
}
In that case, I can pass whatever to it in SomeContext
, or other parameters. When would you need the context.Context
at render time?
The main argument that's provided for this request is to simplify implementing both Templ and Gomponents, but I personally don't see why this would be done at all, and even if it is, there's no friction as you'd just call the appropriate Render
function and pass the required parameters. Any further needed abstractions can be made by the user as per the project requirements
As Adrien said :
Gomponent to Templ conversion
type Gomponent interface {
Render(w io.Writer) error
}
func ToTempl(g Gomponent) templ.Component {
func templ.ComponentFunc(func(ctx context.Context, w io.Writer) error {
return g.Render(w)
})
}
Templ to Gomponent conversion
type gomp struct {
c templ.Component
}
func (g gomp) Render(w io.Writer) error {
return g.c.Render(context.Background(), w)
}
func ToGomponent(c templ.Component) Gomponent {
return g{c: c}
}
I think we can close the issue
Thanks for your input @amrojjeh and @EwenQuim. I'll just close the issue. 😊
Suggested by the article mentioned in #218.