简体   繁体   中英

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:

class TestClass extends React.Component

Do I need to use jsx or can I use js file instead? What are the benefits of using jsx file?

My html file contains the following scripts:

<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?

Thanks a lot!

From Facebook :

You don't have to use JSX with React. You can just use plain JS. However, we recommend using JSX because it is a concise and familiar syntax for defining tree structures with attributes.

In my experience, JSX is much easier to understand at a glance and greatly improves the react experience.

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. Instead follow this Getting Started and use Webpack/Babel/Browserify to convert the code and then deploy it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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