skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search