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

idea : support object literal property value shorthand in jsx syntax #2536

Closed
bloodyowl opened this issue Nov 16, 2014 · 3 comments
Closed

Comments

@bloodyowl
Copy link
Contributor

the idea would be to be able to do :

{this.state.list.map((item, key) => <MyComponent {item, key} />)}

what would you think of it ?

@zpao
Copy link
Member

zpao commented Nov 26, 2014

I'm inclined to say no. We've talked a lot about making use of different syntaxes and we're trying to keep it as minimal as possible. Adding the {...spread} was already a pretty big deal.

cc @sebmarkbage

@sebmarkbage
Copy link
Collaborator

We try to keep syntax discussions over in: https://github.com/facebook/jsx That way we can have a wider group contributing to this syntax to make it worth it's extra weight to the language.

I think that the difference between <Foo {item} />, <Foo {...item} /> and <Foo item /> might be too confusing. The last two are already supported.

I like the way you think though. If you feel strongly about this you should open up an issue at https://github.com/facebook/jsx

@nojvek
Copy link

nojvek commented Jun 10, 2019

facebook/jsx#118

^ A proposal for the object expression syntax as discussed here.

I think that the difference between <Foo {item} />, <Foo {...item} /> and might be too confusing.

Confusion might be relative. <Foo item /> is not very useful since it always evaluates to {item: true}. In hindsight it feels very limited, but I can understand it's behavior from it's html genes. I personally haven't found much use for it.

<Foo {item} /> and <Foo {...item} /> aren't confusing if you look at it from ES8 object notation perspective. {item} is shorthand for {item: item}. {...item} is shorthand for flatten / shallow copy/ spread into a new object.

once someone understands that jsx transpiles to h(name: string | Component, props: {[name]: any}, ...children). ObjectExpression falls in naturally.

It's confusing that <Foo {x} /> is not supported but <Foo {...x} /> is supported. The workaround is
<Foo {...{x}} /> which is a lot more confusing.

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

4 participants