Mention shorthand attribute syntax #11909
Replies: 4 comments 7 replies
-
Seems like a good place for it, yes! But I will say, I know this works, but I know we've discussed this before and there might be a reason we don't document it? Does anyone remember this? 😅 If we do, maybe we could also include the shorthand syntax for boolean attributes, where you can just add e.g.
|
Beta Was this translation helpful? Give feedback.
-
I could have sworn it was in the docs at one point, It is mentioned in the prettier plugin though https://github.com/withastro/prettier-plugin-astro/blob/main/README.md#astro-allow-shorthand |
Beta Was this translation helpful? Give feedback.
-
I personally don't think this needs to be in the docs For example, in the tutorial we leave room for users to discover different ways of doing things (I forget exactly how @sarah11918 describes it) So, is this shorthand something that needs to be included in our docs? The standard way is documented, perhaps this shorthand should be left for users to discover in the same way we guide them via the tutorial but don't teach them everything Of course, if there are other examples where we document this kind of "syntactical sugar" then my point is moot |
Beta Was this translation helpful? Give feedback.
-
I haven't checked to see if any of our code samples use this shorthand (typically we prefer to be explicit, because there's no guarantee anyone knows/understands the shortcut and might think that's a "special Astro thing"), but sort of agree with Matthew in that it's not our job to explain "how JavaScript works." BUT, since the That's why we sort of take the approach of showing the basic concepts that are possible (e.g. creating dynamic HTML by defining variables in frontmatter, using them in the template) and otherwise emphasize differences between Astro and JSX that might surprise you. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
In Astro components, there is a shorthand for assigning a dynamic property if the name of the property and the JS variable is the same.
Given a variable named
href
exists, the following:can be replaced with:
It would be nice if this could be mentioned in the documentation somewhere. The best fitting section in my opinion would be in the dynamic attributes reference.
Beta Was this translation helpful? Give feedback.
All reactions