Skip to content

Instantly share code, notes, and snippets.

@tyler-dot-earth
Last active February 13, 2016 01:55
Show Gist options
  • Save tyler-dot-earth/61a883ff31307cdbbf1b to your computer and use it in GitHub Desktop.
Save tyler-dot-earth/61a883ff31307cdbbf1b to your computer and use it in GitHub Desktop.
JSX "Object Literal Property Value Shorthand"

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment