Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the technical difference between .jsx and .js files

I would like to understand the technical difference between them so as to determine the appropriate one to use.

I've realised that they can both have same content and sometimes used interchangeably in some projects.

How does .jsx files differ from .js?

like image 935
Kosmetika Avatar asked Jan 11 '15 13:01

Kosmetika


People also ask

What is difference between .JS and .JSX file?

JS is standard javascript, JSX is an HTML-like syntax that you can use with React to (theoretically) make it easier and more intuitive to create React components. As the docs say, the only purpose is to make it easier to create React components... there's not much else there.

Is there a difference between adding JSX inside .JS and .JSX files?

As already mentioned, there is no difference, if you create a file with . jsx or . js .

What is a .JSX file?

What is JSX? JSX stands for JavaScript XML. JSX allows us to write HTML in React. JSX makes it easier to write and add HTML in React.

What is difference between JavaScript and Reactjs?

React library has JSX (JavaScript XML), which is HTML like syntax, which is processed into JavaScript calls. React components are reusable which helps while working on larger scale projects and has their own logic and controls. One-way data binding provides better control throughout the application.

What is the difference between JS and JSX?

Difference Between JS and JSX: JS is standard JavaScript, JSX is an HTML-like syntax that you can use with React to (theoretically) make it easier and more intuitive to create React components. As the docs say, the only purpose is to make it easier to create React components... there's not much else there.

Should I convert JSX to JavaScript or keep JSX source code?

If you wish to keep the JSX source code intact for better maintainability, I would keep them as .jsx files. Using the JSX Compiler, either manually or via build script, will convert your JSX syntax to normal JavaScript files.

What is an JSX file?

JSX stands for JavaScript XML. It is a syntax extension for JavaScript that lets you use HTML tags right inside your JavaScript file. Instead of creating, configuring, and appending your HTML tags through JavaScript objects, you can create the elements using an XML-like syntax that will generate the DOM elements for you behind the scenes.

What is the difference between react JSX and JSX tags?

JSX tags ( <Component/>) are clearly not standard javascript and have no special meaning if you put them inside a naked <script> tag for example. Hence all React files that contain them are JSX and not JS. By convention, the entry point of a React application is usually .js instead of .jsx even though it contains React components.


1 Answers

Update for Newer Users

The JSX Compiler tool has been removed as JSXTransformer has been deprecated. The React Team recommends using another tool such as the Babel REPL.


If you wish to keep the JSX source code intact for better maintainability, I would keep them as .jsx files. Using the JSX Compiler, either manually or via build script, will convert your JSX syntax to normal JavaScript files.

Note: It is possible to serve JSX files in your production environment but React will give you console notices about reduced performance.


Personally, I would use something like gulp-jsx or gulp-reactify to convert the files.

Example with gulp-jsx:

var gulp = require('gulp'); var jsx  = require('gulp-jsx');  gulp.task('build', function() {   return gulp.src('path/to/*.jsx')     .pipe(jsx())     .pipe(gulp.dest('dist')); }); 
like image 132
rxgx Avatar answered Oct 10 '22 18:10

rxgx