How to simplify your Rails view layer with ViewComponents. Practical tips and examples.
Hi. Thanks for your content. I've started working with View Components, and your information has helped me a lot.
I tried using the component helper you shared in your talks:
```
def component(name, *args, **kwargs, &block)
render("#{name}_component".classify.constantize.new(*args, **kwargs), &block)
end
But it gave me problems when I nest a VC into another. I found a solution I wanted to share with you because you greatly helped me:
"#{name}_component".classify.constantize.new(*args, **kwargs).render_in(self, &block)
This solution uses the view_context (self) to render the component
Thank you again.
Thanks for sharing 🙌
I made one for "with_collection" too
def component_with_collection(name, *args, **kwargs, &block)
"#{name}_component".classify.constantize.with_collection(*args, **kwargs).render_in(self, &block)
Hi. Thanks for your content. I've started working with View Components, and your information has helped me a lot.
I tried using the component helper you shared in your talks:
```
def component(name, *args, **kwargs, &block)
render("#{name}_component".classify.constantize.new(*args, **kwargs), &block)
end
```
But it gave me problems when I nest a VC into another. I found a solution I wanted to share with you because you greatly helped me:
```
def component(name, *args, **kwargs, &block)
"#{name}_component".classify.constantize.new(*args, **kwargs).render_in(self, &block)
end
```
This solution uses the view_context (self) to render the component
Thank you again.
Thanks for sharing 🙌
I made one for "with_collection" too
```
def component_with_collection(name, *args, **kwargs, &block)
"#{name}_component".classify.constantize.with_collection(*args, **kwargs).render_in(self, &block)
end
```