I'm curious as to how other devs use {{yield}} in components. In my case, I rarely use it. I just usually pass what I would like to {{yield}} into an attribute. I only use {{yield}} when I want the component to act like a web component (which doesn't happen very much).
Any of you guys have like a rule/best practice on when to use {{yield}}?
Don't use {{yield}} if you don't feel any need for it. :)
The benefits of using {{yield}} are:
The natural use for {{yield}} is to decorate a template block with some HTML.
Note that, using this trick, you can pass multiple blocks into a component and yield them in different parts of the component's HTML.
Use yield if you want to use your components in a block form with dynamic content. This is usually useful for example to wrap a area multiple times the same way.
A good example is a input wrapper, that provides some tags and css fun, as well as showing the label, but you yield where you want to put an {{input}} or an <select>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With