Ad

Using React With Or Without Jsx

- 1 answer

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!

Ad

Answer

From Facebook:

You don't have to use JSX with React. You ca" >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.

Ad
source: stackoverflow.com
Ad