Proof of concept / strategy decision: If / When to use properties vs attributes vs slots for complex data. #68
damontgomery
started this conversation in
Ideas
Replies: 1 comment
-
We use slots for content, properties / attributes for configuration when we can. See #57 (comment) for discussion of that approach. Seems to work OK. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Are there best practices / guidelines for using attributes / properties / slots for complex data?
Related in some ways to #57.
Should we use properties, attributes, or slots
<slot name="mySlot"></slot>
in the web components for complex data?Notes
Properties can take complex data such as objects. It can be easier to pass this data in to child components (other web components) or from JS frameworks.
https://lit.dev/docs/templates/expressions/#property-expressions
Attributes can only take simple data. More consumers (such as plain HTML / a CMS) can easily(?) construct these components. They are the default(?) way that Lit handles data / configuration.
https://lit.dev/docs/components/properties/#attributes
Complex data
Complex data such as a list of paired child elements (header / content), can be constructed as a serialized string assigned to an attribute, a data object assigned to a property, or a set of nested
<slot>
child elements.Supporting multiple paths
By default, Lit will convert attributes to properties. This allows the consumer to use either.
It may make sense to use converters to support complex data as both properties or slots, https://lit.dev/docs/components/properties/#conversion-converter
Beta Was this translation helpful? Give feedback.
All reactions