-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend JSXAttributeName by { AssignmentExpression } #22
Conversation
Add support of `{` AssignmentExpression `}` insdie JSX attribute names.
Add support of XJSExpressionContainer as possible name of XJSAttribute
IMHO 👎 Having to use dynamic property names is indicative of a poorly designed component or bad practices, we don't need a dedicated syntax for it. |
There might be an argument for consistency with object literals here. Since it's valid to do: I'm not sure if we would support this in the React transform but I could see this being ok for the broader JSX syntax. Even if we did, we could lint against it. I don't think it's the responsibility of this spec to enforce best-practices. I don't believe this conflicts with any other interpretation of that syntax. So it's plausible. @RReverser, what do you think? |
I already wrote short comment on the original issue: #21 (comment) with "might be possible to spread that value using the spread operator" example. However, afterwards I was somewhat confused by
because this makes sense too, and I couldn't recall good cases where I would need computed attributes.
This currently seems to be the only useful case for computed attributes, but still not sure how often they will be needed per-instance and not per-class. However, it might be useful for some implementations or even for us in future, i.e., if we decide to move import {key as reactKey, ref as reactRef} from 'react/symbols';
var component = <Component [reactKey]="reactKey" key="customProperty" />; So making it part of extended spec but not of current React's implementation seems to be perfect solution to me. |
Yes, I propose this for spec, not to React itself. Since implementations of JSX already can choose to support some feature or not (namespaces). @RReverser you are used here square brackets: So if you will agreed with this feature, you think it should be square brackets like in ES6, but not curly breackets like everywhere else in JSX? |
It was more pseudo-code sample of possible usage. Curly brackets are fine :) |
I'm not sure if I'm buying the consistency argument, it's a slippery slope that by extension means that we "must" support But Symbols is a valid point and it might make sense to support it for that reason. The only thing that sticks out is that Sumbols are not serializeable I believe? I'm not sure if that's actually something we care about anymore, but I know there was talks (quite) some time ago about serializing JSX. Square bracket syntax seems preferable IMHO 👍 (more descriptive and to disambiguate from |
@syranide When we decide to implement it, it can be done with custom serializer support that would recognize and (de-)serialize recognized symbols with simple comparison or ES6 |
It's been half of year already and looks like PR is not mergeable anymore. If we want to get back to it, feel free to open another one. |
@RReverser hah, sure it's not mergeable, because I do not monitor this PR every day.
How I can know if you want it? |
Let's keep the discussion going in #21 and we can decide there. |
Changes to the spec if #21 will be agreed.