Spacer Components introduced in ViewComponent 3.20
Version 3.20 of ViewComponent introduced spacer_component.
It’s a new attribute that can be added to a collection to add another component between each item of a collection. It works like this:
<%= render(ProductComponent.with_collection(@products, spacer_component: SpacerComponent.new)) %>
This will then render SpacerComponent’s between each ProductComponent. Pretty cool.
If you think, you’ve seen this feature before. You could be right. It was inspired by Rails’ collection partial rendering.
I also updated the ViewComponent Cheatsheet to include it.
Want to read me more?
-
Why choose ViewComponent over Rails partials
ViewComponent can help you write cleaner view- and frontend code. But why choose when Rails has partials? -
From Partials (and Helpers) to Embracing ViewComponent in Rails
Step-by-step guide to move from Rails' partials (and helpers) to ViewComponent. A better way organize your app's UI components. -
Components in Rails without gems
This article explores various techniques to get more out of your vanilla Rails partials without needing any gem
Over to you…
What did you like about this article? Learned something knew? Found something is missing or even broken? 🫣 Let me (and others) know!
Comments are powered by Chirp Form
{{comment}}