ReactJS - .JS 与 .JSX [英] ReactJS - .JS vs .JSX

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

问题描述

在使用 React.js 时,我发现有些东西非常令人困惑.

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

互联网上有大量使用 .js 文件和 React 的示例,但许多其他示例使用 .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 .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 和 .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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆