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: <Component { prop: value } /> syntax

rchanou opened this issue · comments

A slightly different take on this request.

Allow curly braces without a preceding prop= to define props. This makes it easy to refactor JSX props into objects by removing the need to change prop=value to prop: value, for each prop.

This is currently a syntax error, so allowing this shouldn't break existing code.

Example:

<Component
  {
    bool: true,
    expr: x + y,
    ...spreadObject
  }
/>

It also has nice symmetry with current spread syntax:

const props = {
  bool: true,
  expr: x + y,
  ...spreadObject
}

// This is already valid JSX
<Component
  {
    ...props
  }
/>

Guess there's already been a lively discussion about this in #23, but I think this is worth being its own issue.