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

(Breaking) Feature Request: Make JSX even more like JS #68

Open
kasperpeulen opened this issue Nov 20, 2016 · 3 comments
Open

(Breaking) Feature Request: Make JSX even more like JS #68

kasperpeulen opened this issue Nov 20, 2016 · 3 comments
Labels
Proposal 2.0 Proposals considerable for JSX 2.0

Comments

@kasperpeulen
Copy link

kasperpeulen commented Nov 20, 2016

I think it is time to make JSX even more like JS and less like HTML. Consider the following JSX:

const name = "Kasper";
const message = <p>Hello, {name}!</p>;
const container = <div>{element}</div>;

What about writing it like this:

const name = "Kasper";
const message = <h1>"Hello, ${name}!"</h1>;
const container = <div>message</div>;

My main subjective reason is that it just looks more right to me. A more objective reason would be that you could introduce javascript comment syntax:

const name = "Kasper";
const message = <h1>"Hello, ${name}!"</h1>;
const container = ( 
  <div>
    // we currently only message the first name
    message
  </div>
);

Similar things could be done for jsx attributes. Instead of:

const element = <Counter count={0}/>;
const element2 = <img src={user.avatarUrl}/>;
const element3 = <div className="header"></div>

I would like it as:

const element = <Counter count=0/>;
const element2 = <img src=user.avatarUrl/>;
const element3 = <div className="header"/>;

Or even better, (I haven't put much thought in this):

const element = <Counter count: 0/>;
const element2 = <img src: user.avatarUrl/>;
const element3 = <div className: "header"/>;

More generally:

<Component
  bool: true,
  num: 1,
  string: "bar",
  expr: x + y,
  valueByPropName,
  ...spreadObject
/>

Inspiration comes from:
https://twitter.com/emilpersson/status/795640485683560449

By just making the syntax more close to javascript, I think many long-standing problems would be more easily fixed:

@gaearon
Copy link

gaearon commented Nov 20, 2016

Please also see the discussion in #65.

@kasperpeulen
Copy link
Author

Seems like this is also how reason implemented jsx:
http://facebook.github.io/reason/#diving-deeper-jsx

@hinell
Copy link

hinell commented Oct 30, 2022

This would be in line with many other tools like that historically use ${foo} to refer to foo variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Proposal 2.0 Proposals considerable for JSX 2.0
Projects
None yet
Development

No branches or pull requests

4 participants