本文介绍了ReactJS-.JS与.JSX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

React中工作时,我感到有些困惑.

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

Internet上有很多示例,它们使用具有响应的.js文件,但还有许多其他示例使用.jsx文件.

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

我已经阅读过有关.jsx文件的信息,我的理解是,它们只是让您在javascript中编写html标签.但是同样的事情也可以写在.js文件中.

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.

那么这两个扩展.js.jsx之间的实际区别是什么?

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

推荐答案

文件扩展名没有.打包器/编译器/无论做什么,都将负责解决其中的文件内容类型.

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

在确定要放入.js.jsx文件类型的内容时,还有其他一些注意事项.由于JSX不是标准的JavaScript,因此有人可以辩称,凡不是普通" JavaScript的内容都应加入自己的扩展名,例如,对于JSX,.jsx以及对于TypeScript,.ts.

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.

这里有一个这里有很好的讨论供阅读

这篇关于ReactJS-.JS与.JSX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 19:05