facebook / jsx

The JSX specification is a XML-like syntax extension to ECMAScript.
http://facebook.github.io/jsx/
1.96k stars 133 forks source link

[feature proposal] JSX "Object Literal Property Value Shorthand" #52

Closed tyler-dot-earth closed 8 years ago

tyler-dot-earth commented 8 years ago

Common problem...

<SomeComponent propVariable={propVariable} />

I repeat "propVariable". I find myself doing this a lot... like, several times for one JSX object (usually a React component) is not uncommon.

Proposed solution...

<SomeComponent [propVariable] />

which would result to the same as the "common problem" example.

EDIT: Dan Abramov suggested this syntax instead:

<SomeComponent {propVariable} />

because "Using square brackets as in computed property name is confusing. In ES6 whatever’s inside brackets is a string name variable" and "[...] would have been more consistent [...]".

Inspired by:

jkoudys commented 8 years ago

Easy enough to do already in ES6 already with a spread + implicit prop names. I don't think we need more syntax muddying the waters when this is already solved.

<SomeComponent {...{propVariable}} />

for the above, or multiple like so:

<AnotherComponent {...{foo, bar, baz}} />
sebmarkbage commented 8 years ago

Duplicate of: https://github.com/facebook/jsx/issues/23

Also, see relevant discussion in: https://github.com/facebook/jsx/issues/37