Search code examples
javascripthtmlreactjsjsxfile-type

ReactJS - .JS vs .JSX


There is something I find very confusing when working in React.js.

There are plenty of examples available on internet which use .js files with React but many others use .jsx files.

I have read about JSX files and my understanding is that they just let you write HTML tags within your JavaScript. But the same thing can be written in JS files as well.

So what is the actual difference between .js and .jsx ?


Solution

  • There is none when it comes to file extensions. Your bundler/transpiler/whatever takes care of resolving what type of file contents there is.

    There are however some other considerations when deciding what to put into a .js or a .jsx file type. Since JSX isn't standard JavaScript one could argue that anything that is not "plain" JavaScript should go into its own extensions ie., .jsx for JSX and .ts for TypeScript for example.

    There's a good discussion here available for read