Skip to content

Are "floating slots" an accepted use case, bad practice, or something new? #1837

Answered by camertron
rhysb27 asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @rhysb27, interesting question! As @boardfish says, this seems fine to me as well, but it's not really how slots were designed to be used. I feel like what you're doing works sort of by accident 😅 It would be more inline with the spirit of the slots API to refactor a bit. Here are a couple of alternative ideas.

Plain 'ol ruby methods

The idea here is to define a method called #status_progress_spinner that returns an instance of the component. The return value can be rendered in the view like any other component. Using a slot instead will wrap the component in an instance of ViewComponent::Slot, which is fine but unnecessary.

app/components/sync_component.rb

class SyncComponent < ViewC…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@rhysb27
Comment options

Comment options

You must be logged in to vote
3 replies
@rhysb27
Comment options

@camertron
Comment options

@reeganviljoen
Comment options

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