facebook / jsx

The JSX specification is a XML-like syntax extension to ECMAScript.

Home Page:http://facebook.github.io/jsx/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Proposal: Syntactic sugar for props with same name as value passed

bcheidemann opened this issue · comments

Take the following component:

const Button = ({ disabled, onClick }) => (
  <button disabled={disabled} onClick={onClick} />
);

This is quite verbose due to the unnecessary repetition of disbabled and onClick.

In JS, we have a similarly verbose syntax which already has a shorthand:

const innerValue = 123;

const obj = {
  innerValue: innerValue,
};

// Equivalent to

const innerValue = 123;

const obj = {
  innerValue,
};

In JSX, it would be nice to be able to do:

const Button = ({ disabled, onClick }) => (
  <button {disabled} {onClick} />
);

This avoids collision with the boolean shorthand and feels consistent with the syntax for spreading props ({...props}).

Whoops - looks like this is a duplicate of #23