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

Use .jsx extension for JSX files instead of .js #52

Closed
dmnd opened this issue Dec 27, 2014 · 19 comments
Closed

Use .jsx extension for JSX files instead of .js #52

dmnd opened this issue Dec 27, 2014 · 19 comments
Labels

Comments

@dmnd
Copy link

dmnd commented Dec 27, 2014

As of React 0.12, it is recommended to use the .jsx file extension rather than the pragma in .js files.

This will also help with editors doing syntax highlighting & linting.

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@buxel
Copy link

buxel commented Jan 3, 2015

+1 to avoid confusion

@frankleng
Copy link

+1

@saitodisse
Copy link

+1 editors syntax highlighting

@seemsindie
Copy link

+1

@koistya
Copy link
Member

koistya commented Feb 4, 2015

Components in the starter kit currently use .js file extension for two reasons:

  1. As of now, it's the default file extension for React components used at Facebook. See react-tools jsx command-line build tool, which ignores .jsx files unless you specified -x jsx parameter. Also see React examples and Flux examples.
  2. You can reference these components in your source code without specifying file extension, e.g. require('./MyComponent') instead of require('./MyComponent.jsx') and still be able to use "navigate to source" feature in your code editor.

Do you think that the benefits of having .jsx file extension for React components outmatch these two?

@sdiaz
Copy link

sdiaz commented Feb 4, 2015

I prefer the use of .js as it's now

@saitodisse
Copy link

good point

@PixnBits
Copy link

PixnBits commented Dec 1, 2015

Every .css file is valid SCSS, but a .scss file may not be valid CSS
Every .js file is valid TypeScript, but a .ts file may not be valid JS (ES3/5/6/2015/2016)
It feels a bit audacious to me that Facebook would put their custom superset into the subset's extension :(

@PixnBits
Copy link

PixnBits commented Dec 1, 2015

FWIW a relevant discussion on this in the React repo:
facebook/react#3582 (comment)

@ehartford
Copy link

jsx isn't valid javascript so, it should not use a .js extension

@koistya
Copy link
Member

koistya commented Mar 1, 2016

@ehartford JSX it's just an extension to JavaScript, not a new language like TypeScript or CoffeeScript. Can you tell the same about async/await stuff which isn't valid JavaScript either?

@PixnBits
Copy link

PixnBits commented Mar 2, 2016

@koistya JSX adds new syntax to ES just as TS does, they're both extensions/supersets that don't follow the ES spec or any stage'd proposal.

FWIW async/await is a Stage 3 proposal, but you raise an interesting point on if proposals TC39 is considering should be considered "valid-enough" ES.

@langpavel
Copy link
Collaborator

Irrelevant. JSX syntax can be used (and it is) in every javascript source file. Closing

@wembernard
Copy link

wembernard commented Sep 23, 2016

@langpavel What about Facebook deprecating react-tools (last comment on facebook/react#832) and recommending .jsx extension?

@koistya You're confused.

JSX is a preprocessor step that adds XML syntax to JavaScript.

Typescript is a typed superset of JavaScript that compiles to plain JavaScript.

See the 2 keywords here: preprocessor, compiles ? Both offer different features but both work the same way.

As a newcomer to the React World, finding jsx syntax inside js is misleading. Everyone here's telling you it's confusing. You do as you please but you're going against your community, that's not really user-centric approach.

@ehartford
Copy link

facebook is recommending using .jsx extension how is this an invalid issue?

@kyeotic
Copy link

kyeotic commented Oct 4, 2016

@ehartford Do you have a link for that, because the link PixnBits posted is React saying not to use .jsx.

@langpavel
Copy link
Collaborator

Create react app does not use jsx too

@koistya
Copy link
Member

koistya commented Oct 4, 2016

@ehartford .jsx is recommended by AirBnb guys, .js by Facebook guys.

@maratbn
Copy link

maratbn commented Oct 18, 2016

Irrelevant. JSX syntax can be used (and it is) in every javascript source file. Closing

If that's so, how come no browser will interpret a JSX <script> unless its 'type' attribute is specified as 'text/babel' (which will tell Babel to interpret it) rather than 'text/javascript' ?

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

No branches or pull requests