Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should React components use the .js or .jsx file extension?

Tags:

html

reactjs

jsx

When I build a component in a react application, I normally use the.js file extension (even if I write in jsx), but I've seen some use the.jsx file extension. Is it better to use .jsx file extensions for components instead of .js? And what's the benefit of doing that?

I use .js file extension and it works without any problem

like image 439
Navindu Dahanayake Avatar asked Sep 05 '25 21:09

Navindu Dahanayake


1 Answers

As @DBS mentioned in one comment, this question has already been asked. But since you are a new member, I'll add a recap to help you understand.

reference from this question ReactJS - .JS vs .JSX

  1. If you make a file with.jsx or.js, it doesn't matter.

  2. JSX is not a standard Javascript extension.

  3. It's only necessary for the transpiler/bundler, which might not be set up to work with JSX files, but might work with JS! You can't use JSX files, so you have to use JS files instead.

  4. .jsx will be seen as a react page, and you are able to identify the difference between React Component and other types of javascript files. Also its features will be applied by extensions automatically

like image 67
Harendrra Avatar answered Sep 08 '25 11:09

Harendrra