Javascript: Whats the reason to always use .jsx instead of .js

Created on 7 Jan 2017  路  3Comments  路  Source: airbnb/javascript

Hello, I would like to know about using .js and .jsx as an extension of the React files:

Are there any differences? Which are?

  • In which cases would the use of .jsx instead of .js is more recommended?
  • This question would be relevant when using: Babel/Webpack for precompiling files?

Thanks

question

Most helpful comment

See the discussion in #985, but essentially, .js should only ever be for files that use features of standard JavaScript - anything nonstandard, like jsx, flow, typescript, or early-stage proposals, needs a different extension. For convenience, we've chosen .jsx but you could choose any unique extension you like.

All 3 comments

See the discussion in #985, but essentially, .js should only ever be for files that use features of standard JavaScript - anything nonstandard, like jsx, flow, typescript, or early-stage proposals, needs a different extension. For convenience, we've chosen .jsx but you could choose any unique extension you like.

.jxs will describe the pupose/contents of the file from a higher level .It'll be easier while navigating to different files across the project.

It seems like the react team at facebook and the airbnb team that own the most popular javascript style guide here are at odds with each other over file extensions.

Airbnb team seems adamant about not having any non standard code in a js file re this issue (#1235)

and this pull https://github.com/airbnb/javascript/pull/985

and names any files with the stuff should have jsx

Facebook team seems adamant that js should be the only extension no matter what is in the file

https://github.com/facebook/create-react-app/issues/87#issuecomment-234627904

For my (and probably others) future reference when setting up a new js repo with the eslint-config-airbnb

Was this page helpful?
0 / 5 - 0 ratings

Related issues

surfaceowl picture surfaceowl  路  3Comments

ehrudxo picture ehrudxo  路  4Comments

progre picture progre  路  3Comments

mismith picture mismith  路  3Comments

graingert picture graingert  路  3Comments