Skip to content

ViewComponent best practices? #3329

Answered by camertron
phil-janeapp asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @phil-janeapp, thanks for asking about this! Glad to hear Primer is useful to you 😄 The ViewComponent website doesn't really talk about specific, in-the-weeds component development, so this is probably the right place to have that conversation.

When do you decide what should go in a slot vs. as an argument?

Great question! IMO there are a couple of things to consider:

  1. Markup. Does the option need to accept markup? If so, then it should probably (read: definitely) be a slot. By opting for a slot, you can benefit from all of Rails' HTML sanitization functionality. If you don't use a slot, you'll have to rely on the component's users passing in HTML-safe strings. Of course, non-sanitiz…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@phil-janeapp
Comment options

@joelhawksley
Comment options

@phil-janeapp
Comment options

@phil-janeapp
Comment options

Answer selected by phil-janeapp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants