简体   繁体   English

在有或没有jsx的情况下使用React

[英]Using React with or without jsx

I'm learning React and not sure how but I was able to run a simple app without jsx, my js file start like that: 我正在学习React并且不确定如何使用,但是我能够在没有jsx的情况下运行一个简单的应用程序,我的js文件开始如下:

class TestClass extends React.Component

Do I need to use jsx or can I use js file instead? 我需要使用jsx还是可以改为使用js文件? What are the benefits of using jsx file? 使用jsx文件有什么好处?

My html file contains the following scripts: 我的html文件包含以下脚本:

<script src="https://fb.me/react-0.14.5.js"></script>
<script src="https://fb.me/react-dom-0.14.5.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.24/browser.min.js"></script>
<script type="text/babel" src="main.js"></script>

Is that the right way of using React in a production environment? 这是在生产环境中使用React的正确方法吗?

Thanks a lot! 非常感谢!

From Facebook : 来自Facebook

You don't have to use JSX with React. 您不必将JSX与React一起使用。 You can just use plain JS. 您可以只使用普通的JS。 However, we recommend using JSX because it is a concise and familiar syntax for defining tree structures with attributes. 但是,我们建议使用JSX,因为它是用于定义带有属性的树结构的简洁且熟悉的语法。

In my experience, JSX is much easier to understand at a glance and greatly improves the react experience. 以我的经验,JSX一目了然容易理解,并且极大地改善了反应体验。

You should not include the browser.min.js script in a production environment because that will require transpiling the code every time the page is loaded. 您不应在生产环境中包含browser.min.js脚本,因为这将要求每次加载页面时都对代码进行编译。 Instead follow this Getting Started and use Webpack/Babel/Browserify to convert the code and then deploy it. 而是遵循此入门指南,并使用Webpack / Babel / Browserify转换代码,然后进行部署。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM