Rendering a component twice #1452
-
I have some use cases where I could imagine rendering a component instance twice. For example, we render our navigation menu markup twice, once for wider screens and once for the small-screen dropdown menu variant. For this, I could imagine re-using the components for the individual menu elements that appear in both menus and call Are there any known downsides to / dangers in doing that, i.e. due to internal state of components during rendering? What do I have to be careful about? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
I don't think you should have any problem instancing a component multiple times, that's what it is made for! |
Beta Was this translation helpful? Give feedback.
I think in this case, you can use
render_in
to render to a string, no need forcapture
: https://viewcomponent.org/guide/getting-started.html#rendering-viewcomponents-to-strings-inside-controller-actions