Skip to content

Instantly share code, notes, and snippets.

@boardfish
Last active March 29, 2022 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boardfish/d84d541c2457056cba025d26cd736872 to your computer and use it in GitHub Desktop.
Save boardfish/d84d541c2457056cba025d26cd736872 to your computer and use it in GitHub Desktop.
<h1>Home#index</h1>
<p>Find me in app/views/home/index.html.erb</p>
<%= render OuterComponent.new do |c| %>
<% c.button { render InnerComponent.new } %>
<% end %>
<div>Add Inner template here</div>
# frozen_string_literal: true
class InnerComponent < ApplicationComponent
end
<div>
<p>OuterComponent</p>
<%= button %>
</div>
# frozen_string_literal: true
class OuterComponent < ApplicationComponent
renders_one :button
end
class OuterComponentPreview < ViewComponent::Preview
def default
render(OuterComponent.new) do |c|
c.button { render(InnerComponent.new) }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment