You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was asking in the Astro Discord if "scoped slots" like Vue has were possible in Astro. Scoped slots allow you to pass values from within the component up to the slot template. This is really useful for building data-driven components that need different layouts. You bind the scoped props to the slot and each layout will have access to them.
It turns out the concept DOES exists in Astro, but it requires a dramatically different approach to define them. Additionally, the docs don't show this approach in the Slots section of the Component docs (there's a ticket to do so withastro/docs#8855)
While it works, the implementation is a huge departure from other slot behaviour. I propose that friendly syntax similar to what Vue does be implemented to make scoped slots easier to build. Let values be bound to the element itself.
I realize this also might require some adjustment to how slots are rendered since Vue lets a slot exist inside a loop.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I was asking in the Astro Discord if "scoped slots" like Vue has were possible in Astro. Scoped slots allow you to pass values from within the component up to the slot template. This is really useful for building data-driven components that need different layouts. You bind the scoped props to the slot and each layout will have access to them.
MyList.vue (component)
Usage
Same component, different slot layout
It turns out the concept DOES exists in Astro, but it requires a dramatically different approach to define them. Additionally, the docs don't show this approach in the Slots section of the Component docs (there's a ticket to do so withastro/docs#8855)
While it works, the implementation is a huge departure from other slot behaviour. I propose that friendly syntax similar to what Vue does be implemented to make scoped slots easier to build. Let values be bound to the element itself.
I realize this also might require some adjustment to how slots are rendered since Vue lets a slot exist inside a loop.
Beta Was this translation helpful? Give feedback.
All reactions