-
Notifications
You must be signed in to change notification settings - Fork 26.6k
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
.jsx
extension cannot be used with React Native
#982
Comments
I've disabled this rule because as you said, it doesn't make sense in the context of an RN app. It might help to add a note in the docs: https://github.com/airbnb/javascript/tree/master/react#naming |
A note would be great, thanks! |
Apart from React Native, it is very common to use .js extensions for files that include JSX. |
@borisyankov "what's common" isn't the primary motivator for this guide, it's "what we use at Airbnb". We believe that |
So how? |
|
@ljharb - Thank you for this, but where should this be inputed? thank you |
@julesmoretti in your |
{
"extends": "airbnb",
+ "rules": {
+ // `.jsx` extension cannot be used with React Native
+ // https://github.com/airbnb/javascript/issues/982
+ "react/jsx-filename-extension": ["error", { "extensions": [".js", ".jsx"] }]
+ }
} |
Everyone that is giving 👎 to @ljharb you clearly do not understand that this is a React Native issue. As he explains, this is the guideline for AirBnB, not the guide line of Javascript community or React ecosystem and they have a really good argument on why this should be like this, Just let me give you one, Go to your code and tell me how many files depends of React components right now 😉 I am pretty much that with Why would you care, Well, go to your code and tell me what could be a potential code that could be shared cross any Javascript environment (NodeJS and Browsers) I am pretty much that it is not the React one, it isn't it?! I hope you get where I am heading. Despite that, React creator invented So, I do not see any issue related to the code style unless AirBnB decide to think otherwise. |
Update: This only works in react-native 57, use the solutions below for later versions Just so everyone one knows it is possible to use JSX files with react native. Inside of the root of your project add a file named // ./rn-cli.config.js
module.exports = {
/// @name Make ReactNative Great Again
/// @description Allows you to enable support for JSX files, and `.mjs` files which is the new node standard
/// @source http://www.fallingcanbedeadly.com/posts/enabling-react-native-jsx-extension
/// @note One caveat, The `index.js` file in the root of your project has to be `.js`.
getSourceExts: () => [ 'jsx', 'mjs', 'js' ],
} |
@tjbenton |
@tjbenton your solution doesn't work in 0.57.3. Any help? |
@stonecold123 @youngjuning try this :
|
Thanks for your help.Chinese will remember you. @Under-Warz |
@Under-Warz's solution no longer works in React Native 0.59. Anyone have a solution? |
Found an answer to React Native 0.59. Move |
You saved me several hours of pulling my hair out from trying to figure out why the old solutions were not working, thanks! |
@taranda's comment is very important for anyone upgrading to 0.59. Thank you for catching that! |
This seems answered (and seems more worthy of an issue on RN itself). |
Since
.jsx
extension cannot be used with React Native (Cf. facebook/react-native#5233), if someone wants to use this config with React Native, the rulereact/jsx-filename-extension
should be set to.js
only instead of.jsx
only.The text was updated successfully, but these errors were encountered: