Skip to content
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

Proposal: allow "nameless" elements to represent plain objects #70

Closed
rchanou opened this issue Feb 11, 2017 · 1 comment
Closed

Proposal: allow "nameless" elements to represent plain objects #70

rchanou opened this issue Feb 11, 2017 · 1 comment

Comments

@rchanou
Copy link

rchanou commented Feb 11, 2017

Example:

const sharedProps = <
  type='button'
  style={{ background: 'red', color: 'white' }}
/>;

const buttonElement = <button 
  {...sharedProps}
  onClick={doSomething} 
/>;

const anotherButtonElement = <button 
  {...sharedProps} 
  onClick={doSomethingElse} 
/>;

The main purpose for allowing this would be to ease refactoring. If you wish to pull out props into an object, currently you have to change prop={value} to prop: value, for all of them. The syntax above allows simple cut-and-paste.

Making JSX more like JS would accomplish the same goal, but this seems less drastic.

Edit: OK, so this might be problematic because spaces are currently allowed between < and the tag name. I just never noticed because I never write it that way. Regardless, some sort of JSX object declaration syntax would be nice.

@rchanou rchanou changed the title Proposal: allow "tagless" elements to represent plain objects Proposal: allow "nameless" elements to represent plain objects Feb 11, 2017
@rchanou
Copy link
Author

rchanou commented Feb 12, 2017

Never mind, I came up with a better proposal.

@rchanou rchanou closed this as completed Feb 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant