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
2
Answers
It depends on your build setup. On some setups writing JSX in a
.js
will not work.But as long as
.js
files with JSX work for you, I don’t see a problem with it.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
If you make a file with.jsx or.js, it doesn’t matter.
JSX is not a standard Javascript extension.
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.
.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