First of all you need to add Babel to transpile your JSX which here is how you would do that by adding this line to your html file:
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
and then you need is to add the type property to your InputField script like this:
<script type="text/babel" src="InputField.js"></script>
Here is the complete code:
<!-- ... existing HTML ... -->
<div id="like_button_container"></div>
<!-- ... existing HTML ... -->
<!-- Load React. -->
<script src="https://unpkg.com/react@18/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js" crossorigin></script>
<!-- Babel js -->
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
<!-- Load our React component. -->
<script type="text/babel" src="InputField.js"></script>
</body>
Answer from Taghi Khavari on Stack Overflowreactjs - How to convert react JSX files to simple JavaScript file [offline transformation] - Stack Overflow
reactjs - React.js - convert .jsx to .js - Stack Overflow
JSX to ES6 converter(online preferably)
What’s the difference between .js & .jsx extension
If you are using babel-cli you need to use a plugin to transform jsx syntax to js syntax that the browser understands. See the following link: http://babeljs.io/docs/plugins/transform-react-jsx/ You'll need to install babel-plugin-transform-react-jsx plugin and use it in a .babelrc file like that:
{
"plugins": ["transform-react-jsx"]
}
Then your babel command should work.
Try babel --presets react JSX_Files --watch --out-dir public/javascripts (s on the end of preset).
Hello dev-devs!
I am looking for an online JSX to ES6x converter for a project. I have come across jscodeshit but I am trying to get the gist of it. Any help is fully appreciated.
Thank you