Why ViewComponents don't have better syntactic sugar? Like a "component" helper #1922
Replies: 4 comments 10 replies
-
Or maybe even something shorter like |
Beta Was this translation helpful? Give feedback.
-
Here's another interesting article: https://evilmartians.com/chronicles/viewcomponent-in-the-wild-supercharging-your-components And another, different solution, to the same problem: https://github.com/x-govuk/govuk-components/blob/main/app/helpers/govuk_components_helper.rb I think that many people would love a standard solution, in order to ensure a consistent naming convention across all Rails applications. |
Beta Was this translation helpful? Give feedback.
-
@collimarco while this isn't the only reason, one cause for hesitation around introducing such a helper is that it likely would lead to ambiguous references to components. For example, if I had a Ambiguous references also make it difficult to pre-compiles Rails templates and components, leaving several avenues for performance optimization off the table. I'd be happy to discuss this further, but figured it'd be helpful to share where at least some of my hesitation lies. |
Beta Was this translation helpful? Give feedback.
-
It would be interesting to take a poll on how users of ViewComponent are using it in the wild. With syntactic sugar or without? I suspect the vast majority do not type We are in the process of adding this to an existing project and using it for the first time. There's at least a half a dozen ways I've found to make life easier on this subject. Wouldn't it be nicer to just standardize on one? |
Beta Was this translation helpful? Give feedback.
-
Compared to Rails helpers, I find the syntax of ViewComponents quite verbose...
This would be much easier to read/write:
Are there any good reasons for not using this more succinct naming?
I also found articles like this that suggest to create your own helper, but I wonder if it's a good idea or not... Why ViewComponents don't provide something similar out of the box?
https://dev.to/scottbarrow/rails-viewcomponent-helper-ibn
Beta Was this translation helpful? Give feedback.
All reactions